
--------------------------------------------------------------------------------
-- PaddleOCR ONNX module
--------------------------------------------------------------------------------

---@type onnxruntime*
local _onnxruntime = require("onnxruntime")

---@type image_cv*
local _image_cv = require("image.cv")

---@alias paddleocr_image_input string|ImageObject*

---@class paddleocr_point*
---@field x number abscissa
---@field y number vertical coordinate

---@class paddleocr_line*
---@field text string Recognize text
---@field confidence number Confidence
---@field box paddleocr_point*[] Text box four point coordinates
---@field x? number abscissa
---@field y? number vertical coordinate
---@field width? number Width
---@field height? number height

---@class paddleocr_result*
---@field text string Recognize text and splice it line by line
---@field lines paddleocr_line*[] text line list
---@field stats? table Batch identification statistics

---@class paddleocr_options*
---@field det_model_path? string Detect model path
---@field rec_model_path? string Identify model paths
---@field dict_path? string dictionary path
---@field det_model_dir? string Detection model directory
---@field rec_model_dir? string Identify model directory
---@field model_dir? string Model root directory
---@field providers? string[] ONNX Runtime provider list
---@field fallback_to_cpu? boolean provider Fallback CPU on failure
---@field threads? integer Number of threads
---@field max_side_len? integer Detect longest side
---@field det_db_thresh? number DB threshold
---@field det_db_box_thresh? number DB box threshold
---@field det_db_unclip_ratio? number DB expansion ratio
---@field det_db_use_dilate? boolean Whether to expand
---@field det_use_polygon_score? boolean Whether to use polygon scoring
---@field rec_batch? boolean Whether to identify batches
---@field rec_batch_size? integer batch size
---@field rec_batch_min_size? integer Minimum batch quantity
---@field rec_bucket_width? boolean Whether to bucket by width
---@field rec_bucket_width_stride? integer width bucket step
---@field use_space_char? boolean Whether to use space characters
---@field coreml_compute_units? 'all'|'cpu_only'|'cpu_and_gpu'|'cpu_and_neural_engine' CoreML computing unit
---@field coreml_enable_on_subgraph? boolean Whether to enable CoreML in subgraphs
---@field coreml_require_static_input_shapes? boolean Whether to require static input shape
---@field coreml_create_mlprogram? boolean Whether to create MLProgram

---@class paddleocr_call_options*
---@field return_text_only? boolean Whether to return only text
---@field return_details? boolean Whether to return detailed information
---@field stats? boolean Whether to return statistical information

---@class paddleocr_model_info*
---@field mode? 'det'|'rec' mode
---@field model_path? string model path
---@field used_coreml? boolean Whether to use CoreML EP
---@field input_name? string Enter name
---@field input_shape? integer[] Enter shape
---@field providers? string[] provider list
---@field outputs? { name: string, shape: integer[] }[] Output information

---@class paddleocr_session_info*
---@field session onnxruntime_session* ONNX Runtime session
---@field model_path string model path
---@field dict_path? string Dictionary path, only recognizes that the model exists
---@field input_name string Enter name
---@field output_names string[] output name
---@field model_info paddleocr_model_info* Model information

---@class paddleocr_det_config*
---@field max_side_len integer Detect longest side
---@field det_db_thresh number DB threshold
---@field det_db_box_thresh number DB box threshold
---@field det_db_unclip_ratio number DB expansion ratio
---@field det_db_use_dilate boolean Whether to expand
---@field det_use_polygon_score boolean Whether to use polygon scoring

---@class paddleocr_rec_config*
---@field batch boolean Whether to identify batches
---@field batch_size integer batch size
---@field batch_min_size integer Minimum batch quantity
---@field bucket_width boolean Whether to bucket by width
---@field bucket_width_stride integer width bucket step

---@class paddleocr_model_info_result*
---@field rec paddleocr_model_info* Identify model information
---@field det? paddleocr_model_info* Detection model information
---@field dict_path? string dictionary path
---@field det_config paddleocr_det_config* Detect configuration
---@field rec_config paddleocr_rec_config* Identify configuration

---@class paddleocr_instance*
---@field closed boolean Is it closed
---@field rec paddleocr_session_info* Identify session information
---@field det? paddleocr_session_info* Check session information
---@field charset string[] character set
---@field det_config paddleocr_det_config* Detect configuration
---@field rec_config paddleocr_rec_config* Identify configuration
local paddleocr_instance = {}

---@class paddleocr_onnx*
---@field VERSION string module version
---@field AUTHOR string Author
---@type paddleocr_onnx*
local M = {}

--- Create OCR instance
---@param opts? paddleocr_options* Options
---@return paddleocr_instance* ocr OCR Example
function M.new(opts) end

--- Create OCR instance
---@param opts? paddleocr_options* Options
---@return paddleocr_instance* ocr OCR Example
function M.create(opts) end

--- Create OCR instance
---@param opts? paddleocr_options* Options
---@return paddleocr_instance* ocr OCR Example
function M.open(opts) end

--- Recognize the entire picture
---@param input paddleocr_image_input Image path, image data, or image object
---@param opts? paddleocr_call_options* Options
---@return paddleocr_result|string result Recognition results, return text when return_text_only is true
function paddleocr_instance:recognize(input, opts) end

--- Recognize single line text images
---@param input paddleocr_image_input Image path, image data, or image object
---@param opts? paddleocr_call_options* Options
---@return paddleocr_line|string line Recognition results, return text when return_text_only is true
function paddleocr_instance:recognize_line(input, opts) end

--- Recognize single line text images
---@param input paddleocr_image_input Image path, image data, or image object
---@param opts? paddleocr_call_options* Options
---@return paddleocr_line|string line Recognition results, text can be returned by default
function paddleocr_instance:classification(input, opts) end

--- Recognize the entire picture
---@param input paddleocr_image_input Image path, image data, or image object
---@param opts? paddleocr_call_options* Options
---@return paddleocr_result|string result Recognition results
function paddleocr_instance:ocr(input, opts) end

--- Only detect text boxes
---@param input paddleocr_image_input Image path, image data, or image object
---@return paddleocr_line*[] lines Text box list
function paddleocr_instance:detect(input) end

--- Only detect text boxes
---@param input paddleocr_image_input Image path, image data, or image object
---@return paddleocr_line*[] lines Text box list
function paddleocr_instance:det(input) end

--- Get model information
---@return paddleocr_model_info_result* info Model information
function paddleocr_instance:get_model_info() end

--- Close instance
function paddleocr_instance:close() end

return M
