# coding: utf-8

"""
    Docling Serve

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from yfkm3_services_parse_client.models.code_formula_custom_config import CodeFormulaCustomConfig
from yfkm3_services_parse_client.models.image_ref_mode import ImageRefMode
from yfkm3_services_parse_client.models.input_format import InputFormat
from yfkm3_services_parse_client.models.ocr_engines_enum import OcrEnginesEnum
from yfkm3_services_parse_client.models.output_format import OutputFormat
from yfkm3_services_parse_client.models.pdf_backend import PdfBackend
from yfkm3_services_parse_client.models.picture_description_api import PictureDescriptionApi
from yfkm3_services_parse_client.models.picture_description_custom_config import PictureDescriptionCustomConfig
from yfkm3_services_parse_client.models.picture_description_local import PictureDescriptionLocal
from yfkm3_services_parse_client.models.processing_pipeline import ProcessingPipeline
from yfkm3_services_parse_client.models.provider_kind import ProviderKind
from yfkm3_services_parse_client.models.table_former_mode import TableFormerMode
from yfkm3_services_parse_client.models.vlm_model_api import VlmModelApi
from yfkm3_services_parse_client.models.vlm_model_local import VlmModelLocal
from yfkm3_services_parse_client.models.vlm_model_type import VlmModelType
from yfkm3_services_parse_client.models.vlm_pipeline_custom_config import VlmPipelineCustomConfig
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class ConvertDocumentsRequestOptions(BaseModel):
    """
    ConvertDocumentsRequestOptions
    """ # noqa: E501
    from_formats: Optional[List[InputFormat]] = Field(default=None, description="Input format(s) to convert from. String or list of strings. Allowed values: docx, pptx, html, image, pdf, asciidoc, md, csv, xlsx, xml_uspto, xml_jats, xml_xbrl, mets_gbs, json_docling, audio, vtt, latex. Optional, defaults to all formats.")
    to_formats: Optional[List[OutputFormat]] = Field(default=None, description="Output format(s) to convert to. String or list of strings. Allowed values: md, json, yaml, html, html_split_page, text, doctags, vtt. Optional, defaults to Markdown.")
    image_export_mode: Optional[ImageRefMode] = Field(default=None, description="Image export mode for the document (in case of JSON, Markdown or HTML). Allowed values: placeholder, embedded, referenced. Optional, defaults to Embedded.")
    do_ocr: Optional[StrictBool] = Field(default=True, description="If enabled, the bitmap content will be processed using OCR. Boolean. Optional, defaults to true")
    force_ocr: Optional[StrictBool] = Field(default=False, description="If enabled, replace existing text with OCR-generated text over content. Boolean. Optional, defaults to false.")
    ocr_engine: Optional[OcrEnginesEnum] = Field(default=None, description="The OCR engine to use. String. Allowed values: auto, easyocr, kserve_v2_ocr, ocrmac, rapidocr, tesserocr, tesseract. Optional, defaults to easyocr.")
    ocr_lang: Optional[List[StrictStr]] = None
    ocr_preset: Optional[StrictStr] = Field(default='auto', description="Preset ID for OCR engine.")
    ocr_custom_config: Optional[Dict[str, Any]] = None
    pdf_backend: Optional[PdfBackend] = Field(default=None, description="The PDF backend to use. String. Allowed values: pypdfium2, docling_parse, dlparse_v1, dlparse_v2, dlparse_v4. Optional, defaults to pypdfium2.")
    table_mode: Optional[TableFormerMode] = Field(default=None, description="Mode to use for table structure, String. Allowed values: fast, accurate. Optional, defaults to accurate.")
    table_cell_matching: Optional[StrictBool] = Field(default=True, description="If true, matches table cells predictions back to PDF cells. Can break table output if PDF cells are merged across table columns. If false, let table structure model define the text cells, ignore PDF cells.")
    pipeline: Optional[ProcessingPipeline] = Field(default=None, description="Choose the pipeline to process PDF or image files.")
    page_range: Optional[Any] = None
    document_timeout: Optional[Union[Annotated[float, Field(le=604800.0, strict=True, gt=0.0)], Annotated[int, Field(le=604800, strict=True, gt=0)]]] = Field(default=604800.0, description="The timeout for processing each document, in seconds.")
    abort_on_error: Optional[StrictBool] = Field(default=False, description="Abort on error if enabled. Boolean. Optional, defaults to false.")
    do_table_structure: Optional[StrictBool] = Field(default=True, description="If enabled, the table structure will be extracted. Boolean. Optional, defaults to true.")
    include_images: Optional[StrictBool] = Field(default=True, description="If enabled, images will be extracted from the document. Boolean. Optional, defaults to true.")
    images_scale: Optional[Union[StrictFloat, StrictInt]] = Field(default=2.0, description="Scale factor for images. Float. Optional, defaults to 2.0.")
    md_page_break_placeholder: Optional[StrictStr] = Field(default='', description="Add this placeholder between pages in the markdown output.")
    do_code_enrichment: Optional[StrictBool] = Field(default=False, description="If enabled, perform OCR code enrichment. Boolean. Optional, defaults to false.")
    do_formula_enrichment: Optional[StrictBool] = Field(default=False, description="If enabled, perform formula OCR, return LaTeX code. Boolean. Optional, defaults to false.")
    do_picture_classification: Optional[StrictBool] = Field(default=False, description="If enabled, classify pictures in documents. Boolean. Optional, defaults to false.")
    do_chart_extraction: Optional[StrictBool] = Field(default=False, description="If enabled, extract numeric data from charts. Boolean. Optional, defaults to false.")
    do_picture_description: Optional[StrictBool] = Field(default=False, description="If enabled, describe pictures in documents. Boolean. Optional, defaults to false.")
    picture_description_area_threshold: Optional[Union[StrictFloat, StrictInt]] = Field(default=0.05, description="Minimum percentage of the area for a picture to be processed with the models.")
    picture_description_local: Optional[PictureDescriptionLocal] = None
    picture_description_api: Optional[PictureDescriptionApi] = None
    vlm_pipeline_model: Optional[VlmModelType] = None
    vlm_pipeline_model_local: Optional[VlmModelLocal] = None
    vlm_pipeline_model_api: Optional[VlmModelApi] = None
    vlm_pipeline_preset: Optional[StrictStr] = None
    picture_description_preset: Optional[StrictStr] = None
    code_formula_preset: Optional[StrictStr] = None
    vlm_pipeline_custom_config: Optional[VlmPipelineCustomConfig] = None
    picture_description_custom_config: Optional[PictureDescriptionCustomConfig] = None
    code_formula_custom_config: Optional[CodeFormulaCustomConfig] = None
    table_structure_preset: Optional[StrictStr] = None
    table_structure_custom_config: Optional[Dict[str, Any]] = None
    layout_custom_config: Optional[Dict[str, Any]] = None
    layout_preset: Optional[StrictStr] = None
    picture_classification_preset: Optional[StrictStr] = None
    picture_classification_custom_config: Optional[Dict[str, Any]] = None
    provider: Optional[ProviderKind] = Field(default=None, description="Execution provider to use.")
    chunk: Optional[StrictBool] = Field(default=True, description="If true, the convert endpoint returns chunked output instead of plain document output.")
    __properties: ClassVar[List[str]] = ["from_formats", "to_formats", "image_export_mode", "do_ocr", "force_ocr", "ocr_engine", "ocr_lang", "ocr_preset", "ocr_custom_config", "pdf_backend", "table_mode", "table_cell_matching", "pipeline", "page_range", "document_timeout", "abort_on_error", "do_table_structure", "include_images", "images_scale", "md_page_break_placeholder", "do_code_enrichment", "do_formula_enrichment", "do_picture_classification", "do_chart_extraction", "do_picture_description", "picture_description_area_threshold", "picture_description_local", "picture_description_api", "vlm_pipeline_model", "vlm_pipeline_model_local", "vlm_pipeline_model_api", "vlm_pipeline_preset", "picture_description_preset", "code_formula_preset", "vlm_pipeline_custom_config", "picture_description_custom_config", "code_formula_custom_config", "table_structure_preset", "table_structure_custom_config", "layout_custom_config", "layout_preset", "picture_classification_preset", "picture_classification_custom_config", "provider", "chunk"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of ConvertDocumentsRequestOptions from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of picture_description_local
        if self.picture_description_local:
            _dict['picture_description_local'] = self.picture_description_local.to_dict()
        # override the default output from pydantic by calling `to_dict()` of picture_description_api
        if self.picture_description_api:
            _dict['picture_description_api'] = self.picture_description_api.to_dict()
        # override the default output from pydantic by calling `to_dict()` of vlm_pipeline_model_local
        if self.vlm_pipeline_model_local:
            _dict['vlm_pipeline_model_local'] = self.vlm_pipeline_model_local.to_dict()
        # override the default output from pydantic by calling `to_dict()` of vlm_pipeline_model_api
        if self.vlm_pipeline_model_api:
            _dict['vlm_pipeline_model_api'] = self.vlm_pipeline_model_api.to_dict()
        # override the default output from pydantic by calling `to_dict()` of vlm_pipeline_custom_config
        if self.vlm_pipeline_custom_config:
            _dict['vlm_pipeline_custom_config'] = self.vlm_pipeline_custom_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of picture_description_custom_config
        if self.picture_description_custom_config:
            _dict['picture_description_custom_config'] = self.picture_description_custom_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of code_formula_custom_config
        if self.code_formula_custom_config:
            _dict['code_formula_custom_config'] = self.code_formula_custom_config.to_dict()
        # set to None if ocr_lang (nullable) is None
        # and model_fields_set contains the field
        if self.ocr_lang is None and "ocr_lang" in self.model_fields_set:
            _dict['ocr_lang'] = None

        # set to None if ocr_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.ocr_custom_config is None and "ocr_custom_config" in self.model_fields_set:
            _dict['ocr_custom_config'] = None

        # set to None if page_range (nullable) is None
        # and model_fields_set contains the field
        if self.page_range is None and "page_range" in self.model_fields_set:
            _dict['page_range'] = None

        # set to None if picture_description_local (nullable) is None
        # and model_fields_set contains the field
        if self.picture_description_local is None and "picture_description_local" in self.model_fields_set:
            _dict['picture_description_local'] = None

        # set to None if picture_description_api (nullable) is None
        # and model_fields_set contains the field
        if self.picture_description_api is None and "picture_description_api" in self.model_fields_set:
            _dict['picture_description_api'] = None

        # set to None if vlm_pipeline_model (nullable) is None
        # and model_fields_set contains the field
        if self.vlm_pipeline_model is None and "vlm_pipeline_model" in self.model_fields_set:
            _dict['vlm_pipeline_model'] = None

        # set to None if vlm_pipeline_model_local (nullable) is None
        # and model_fields_set contains the field
        if self.vlm_pipeline_model_local is None and "vlm_pipeline_model_local" in self.model_fields_set:
            _dict['vlm_pipeline_model_local'] = None

        # set to None if vlm_pipeline_model_api (nullable) is None
        # and model_fields_set contains the field
        if self.vlm_pipeline_model_api is None and "vlm_pipeline_model_api" in self.model_fields_set:
            _dict['vlm_pipeline_model_api'] = None

        # set to None if vlm_pipeline_preset (nullable) is None
        # and model_fields_set contains the field
        if self.vlm_pipeline_preset is None and "vlm_pipeline_preset" in self.model_fields_set:
            _dict['vlm_pipeline_preset'] = None

        # set to None if picture_description_preset (nullable) is None
        # and model_fields_set contains the field
        if self.picture_description_preset is None and "picture_description_preset" in self.model_fields_set:
            _dict['picture_description_preset'] = None

        # set to None if code_formula_preset (nullable) is None
        # and model_fields_set contains the field
        if self.code_formula_preset is None and "code_formula_preset" in self.model_fields_set:
            _dict['code_formula_preset'] = None

        # set to None if vlm_pipeline_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.vlm_pipeline_custom_config is None and "vlm_pipeline_custom_config" in self.model_fields_set:
            _dict['vlm_pipeline_custom_config'] = None

        # set to None if picture_description_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.picture_description_custom_config is None and "picture_description_custom_config" in self.model_fields_set:
            _dict['picture_description_custom_config'] = None

        # set to None if code_formula_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.code_formula_custom_config is None and "code_formula_custom_config" in self.model_fields_set:
            _dict['code_formula_custom_config'] = None

        # set to None if table_structure_preset (nullable) is None
        # and model_fields_set contains the field
        if self.table_structure_preset is None and "table_structure_preset" in self.model_fields_set:
            _dict['table_structure_preset'] = None

        # set to None if table_structure_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.table_structure_custom_config is None and "table_structure_custom_config" in self.model_fields_set:
            _dict['table_structure_custom_config'] = None

        # set to None if layout_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.layout_custom_config is None and "layout_custom_config" in self.model_fields_set:
            _dict['layout_custom_config'] = None

        # set to None if layout_preset (nullable) is None
        # and model_fields_set contains the field
        if self.layout_preset is None and "layout_preset" in self.model_fields_set:
            _dict['layout_preset'] = None

        # set to None if picture_classification_preset (nullable) is None
        # and model_fields_set contains the field
        if self.picture_classification_preset is None and "picture_classification_preset" in self.model_fields_set:
            _dict['picture_classification_preset'] = None

        # set to None if picture_classification_custom_config (nullable) is None
        # and model_fields_set contains the field
        if self.picture_classification_custom_config is None and "picture_classification_custom_config" in self.model_fields_set:
            _dict['picture_classification_custom_config'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ConvertDocumentsRequestOptions from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "from_formats": obj.get("from_formats"),
            "to_formats": obj.get("to_formats"),
            "image_export_mode": obj.get("image_export_mode"),
            "do_ocr": obj.get("do_ocr") if obj.get("do_ocr") is not None else True,
            "force_ocr": obj.get("force_ocr") if obj.get("force_ocr") is not None else False,
            "ocr_engine": obj.get("ocr_engine"),
            "ocr_lang": obj.get("ocr_lang"),
            "ocr_preset": obj.get("ocr_preset") if obj.get("ocr_preset") is not None else 'auto',
            "ocr_custom_config": obj.get("ocr_custom_config"),
            "pdf_backend": obj.get("pdf_backend"),
            "table_mode": obj.get("table_mode"),
            "table_cell_matching": obj.get("table_cell_matching") if obj.get("table_cell_matching") is not None else True,
            "pipeline": obj.get("pipeline"),
            "page_range": obj.get("page_range"),
            "document_timeout": obj.get("document_timeout") if obj.get("document_timeout") is not None else 604800.0,
            "abort_on_error": obj.get("abort_on_error") if obj.get("abort_on_error") is not None else False,
            "do_table_structure": obj.get("do_table_structure") if obj.get("do_table_structure") is not None else True,
            "include_images": obj.get("include_images") if obj.get("include_images") is not None else True,
            "images_scale": obj.get("images_scale") if obj.get("images_scale") is not None else 2.0,
            "md_page_break_placeholder": obj.get("md_page_break_placeholder") if obj.get("md_page_break_placeholder") is not None else '',
            "do_code_enrichment": obj.get("do_code_enrichment") if obj.get("do_code_enrichment") is not None else False,
            "do_formula_enrichment": obj.get("do_formula_enrichment") if obj.get("do_formula_enrichment") is not None else False,
            "do_picture_classification": obj.get("do_picture_classification") if obj.get("do_picture_classification") is not None else False,
            "do_chart_extraction": obj.get("do_chart_extraction") if obj.get("do_chart_extraction") is not None else False,
            "do_picture_description": obj.get("do_picture_description") if obj.get("do_picture_description") is not None else False,
            "picture_description_area_threshold": obj.get("picture_description_area_threshold") if obj.get("picture_description_area_threshold") is not None else 0.05,
            "picture_description_local": PictureDescriptionLocal.from_dict(obj["picture_description_local"]) if obj.get("picture_description_local") is not None else None,
            "picture_description_api": PictureDescriptionApi.from_dict(obj["picture_description_api"]) if obj.get("picture_description_api") is not None else None,
            "vlm_pipeline_model": obj.get("vlm_pipeline_model"),
            "vlm_pipeline_model_local": VlmModelLocal.from_dict(obj["vlm_pipeline_model_local"]) if obj.get("vlm_pipeline_model_local") is not None else None,
            "vlm_pipeline_model_api": VlmModelApi.from_dict(obj["vlm_pipeline_model_api"]) if obj.get("vlm_pipeline_model_api") is not None else None,
            "vlm_pipeline_preset": obj.get("vlm_pipeline_preset"),
            "picture_description_preset": obj.get("picture_description_preset"),
            "code_formula_preset": obj.get("code_formula_preset"),
            "vlm_pipeline_custom_config": VlmPipelineCustomConfig.from_dict(obj["vlm_pipeline_custom_config"]) if obj.get("vlm_pipeline_custom_config") is not None else None,
            "picture_description_custom_config": PictureDescriptionCustomConfig.from_dict(obj["picture_description_custom_config"]) if obj.get("picture_description_custom_config") is not None else None,
            "code_formula_custom_config": CodeFormulaCustomConfig.from_dict(obj["code_formula_custom_config"]) if obj.get("code_formula_custom_config") is not None else None,
            "table_structure_preset": obj.get("table_structure_preset"),
            "table_structure_custom_config": obj.get("table_structure_custom_config"),
            "layout_custom_config": obj.get("layout_custom_config"),
            "layout_preset": obj.get("layout_preset"),
            "picture_classification_preset": obj.get("picture_classification_preset"),
            "picture_classification_custom_config": obj.get("picture_classification_custom_config"),
            "provider": obj.get("provider"),
            "chunk": obj.get("chunk") if obj.get("chunk") is not None else True
        })
        return _obj


