from __future__ import annotations

from collections.abc import Mapping
from typing import Any, Literal, TypeVar, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.partition_parameters_params_hi_res_model_name_type_0 import PartitionParametersParamsHiResModelNameType0
from ..models.partition_parameters_params_strategy_type_0 import PartitionParametersParamsStrategyType0
from ..types import UNSET, Unset

T = TypeVar("T", bound="PartitionParametersParams")


@_attrs_define
class PartitionParametersParams:
    """
    Attributes:
        chunking_strategy (Literal['by_title'] | None | Unset):
        combine_under_n_chars (int | None | Unset):
        coordinates (bool | None | Unset):
        encoding (None | str | Unset):
        extract_image_block_types (list[str] | None | Unset):
        gz_uncompressed_content_type (None | str | Unset):
        hi_res_model_name (None | PartitionParametersParamsHiResModelNameType0 | Unset):
        include_page_breaks (bool | None | Unset):
        languages (list[str] | None | Unset):
        max_characters (int | None | Unset):
        multipage_sections (bool | None | Unset):
        new_after_n_chars (int | None | Unset):
        output_format (None | str | Unset):
        overlap (int | None | Unset):
        overlap_all (bool | None | Unset):
        pdf_infer_table_structure (bool | None | Unset):
        skip_infer_table_types (list[str] | None | Unset):
        split_pdf_page (bool | None | Unset):
        strategy (None | PartitionParametersParamsStrategyType0 | Unset):
        xml_keep_tags (bool | None | Unset):
    """

    chunking_strategy: Literal["by_title"] | None | Unset = UNSET
    combine_under_n_chars: int | None | Unset = UNSET
    coordinates: bool | None | Unset = UNSET
    encoding: None | str | Unset = UNSET
    extract_image_block_types: list[str] | None | Unset = UNSET
    gz_uncompressed_content_type: None | str | Unset = UNSET
    hi_res_model_name: None | PartitionParametersParamsHiResModelNameType0 | Unset = UNSET
    include_page_breaks: bool | None | Unset = UNSET
    languages: list[str] | None | Unset = UNSET
    max_characters: int | None | Unset = UNSET
    multipage_sections: bool | None | Unset = UNSET
    new_after_n_chars: int | None | Unset = UNSET
    output_format: None | str | Unset = UNSET
    overlap: int | None | Unset = UNSET
    overlap_all: bool | None | Unset = UNSET
    pdf_infer_table_structure: bool | None | Unset = UNSET
    skip_infer_table_types: list[str] | None | Unset = UNSET
    split_pdf_page: bool | None | Unset = UNSET
    strategy: None | PartitionParametersParamsStrategyType0 | Unset = UNSET
    xml_keep_tags: bool | None | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        chunking_strategy: Literal["by_title"] | None | Unset
        if isinstance(self.chunking_strategy, Unset):
            chunking_strategy = UNSET
        else:
            chunking_strategy = self.chunking_strategy

        combine_under_n_chars: int | None | Unset
        if isinstance(self.combine_under_n_chars, Unset):
            combine_under_n_chars = UNSET
        else:
            combine_under_n_chars = self.combine_under_n_chars

        coordinates: bool | None | Unset
        if isinstance(self.coordinates, Unset):
            coordinates = UNSET
        else:
            coordinates = self.coordinates

        encoding: None | str | Unset
        if isinstance(self.encoding, Unset):
            encoding = UNSET
        else:
            encoding = self.encoding

        extract_image_block_types: list[str] | None | Unset
        if isinstance(self.extract_image_block_types, Unset):
            extract_image_block_types = UNSET
        elif isinstance(self.extract_image_block_types, list):
            extract_image_block_types = self.extract_image_block_types

        else:
            extract_image_block_types = self.extract_image_block_types

        gz_uncompressed_content_type: None | str | Unset
        if isinstance(self.gz_uncompressed_content_type, Unset):
            gz_uncompressed_content_type = UNSET
        else:
            gz_uncompressed_content_type = self.gz_uncompressed_content_type

        hi_res_model_name: None | str | Unset
        if isinstance(self.hi_res_model_name, Unset):
            hi_res_model_name = UNSET
        elif isinstance(self.hi_res_model_name, PartitionParametersParamsHiResModelNameType0):
            hi_res_model_name = self.hi_res_model_name.value
        else:
            hi_res_model_name = self.hi_res_model_name

        include_page_breaks: bool | None | Unset
        if isinstance(self.include_page_breaks, Unset):
            include_page_breaks = UNSET
        else:
            include_page_breaks = self.include_page_breaks

        languages: list[str] | None | Unset
        if isinstance(self.languages, Unset):
            languages = UNSET
        elif isinstance(self.languages, list):
            languages = self.languages

        else:
            languages = self.languages

        max_characters: int | None | Unset
        if isinstance(self.max_characters, Unset):
            max_characters = UNSET
        else:
            max_characters = self.max_characters

        multipage_sections: bool | None | Unset
        if isinstance(self.multipage_sections, Unset):
            multipage_sections = UNSET
        else:
            multipage_sections = self.multipage_sections

        new_after_n_chars: int | None | Unset
        if isinstance(self.new_after_n_chars, Unset):
            new_after_n_chars = UNSET
        else:
            new_after_n_chars = self.new_after_n_chars

        output_format: None | str | Unset
        if isinstance(self.output_format, Unset):
            output_format = UNSET
        else:
            output_format = self.output_format

        overlap: int | None | Unset
        if isinstance(self.overlap, Unset):
            overlap = UNSET
        else:
            overlap = self.overlap

        overlap_all: bool | None | Unset
        if isinstance(self.overlap_all, Unset):
            overlap_all = UNSET
        else:
            overlap_all = self.overlap_all

        pdf_infer_table_structure: bool | None | Unset
        if isinstance(self.pdf_infer_table_structure, Unset):
            pdf_infer_table_structure = UNSET
        else:
            pdf_infer_table_structure = self.pdf_infer_table_structure

        skip_infer_table_types: list[str] | None | Unset
        if isinstance(self.skip_infer_table_types, Unset):
            skip_infer_table_types = UNSET
        elif isinstance(self.skip_infer_table_types, list):
            skip_infer_table_types = self.skip_infer_table_types

        else:
            skip_infer_table_types = self.skip_infer_table_types

        split_pdf_page: bool | None | Unset
        if isinstance(self.split_pdf_page, Unset):
            split_pdf_page = UNSET
        else:
            split_pdf_page = self.split_pdf_page

        strategy: None | str | Unset
        if isinstance(self.strategy, Unset):
            strategy = UNSET
        elif isinstance(self.strategy, PartitionParametersParamsStrategyType0):
            strategy = self.strategy.value
        else:
            strategy = self.strategy

        xml_keep_tags: bool | None | Unset
        if isinstance(self.xml_keep_tags, Unset):
            xml_keep_tags = UNSET
        else:
            xml_keep_tags = self.xml_keep_tags

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if chunking_strategy is not UNSET:
            field_dict["chunking_strategy"] = chunking_strategy
        if combine_under_n_chars is not UNSET:
            field_dict["combine_under_n_chars"] = combine_under_n_chars
        if coordinates is not UNSET:
            field_dict["coordinates"] = coordinates
        if encoding is not UNSET:
            field_dict["encoding"] = encoding
        if extract_image_block_types is not UNSET:
            field_dict["extract_image_block_types"] = extract_image_block_types
        if gz_uncompressed_content_type is not UNSET:
            field_dict["gz_uncompressed_content_type"] = gz_uncompressed_content_type
        if hi_res_model_name is not UNSET:
            field_dict["hi_res_model_name"] = hi_res_model_name
        if include_page_breaks is not UNSET:
            field_dict["include_page_breaks"] = include_page_breaks
        if languages is not UNSET:
            field_dict["languages"] = languages
        if max_characters is not UNSET:
            field_dict["max_characters"] = max_characters
        if multipage_sections is not UNSET:
            field_dict["multipage_sections"] = multipage_sections
        if new_after_n_chars is not UNSET:
            field_dict["new_after_n_chars"] = new_after_n_chars
        if output_format is not UNSET:
            field_dict["output_format"] = output_format
        if overlap is not UNSET:
            field_dict["overlap"] = overlap
        if overlap_all is not UNSET:
            field_dict["overlap_all"] = overlap_all
        if pdf_infer_table_structure is not UNSET:
            field_dict["pdf_infer_table_structure"] = pdf_infer_table_structure
        if skip_infer_table_types is not UNSET:
            field_dict["skip_infer_table_types"] = skip_infer_table_types
        if split_pdf_page is not UNSET:
            field_dict["split_pdf_page"] = split_pdf_page
        if strategy is not UNSET:
            field_dict["strategy"] = strategy
        if xml_keep_tags is not UNSET:
            field_dict["xml_keep_tags"] = xml_keep_tags

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)

        def _parse_chunking_strategy(data: object) -> Literal["by_title"] | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            chunking_strategy_type_0 = cast(Literal["by_title"], data)
            if chunking_strategy_type_0 != "by_title":
                raise ValueError(
                    f"chunking_strategy_type_0 must match const 'by_title', got '{chunking_strategy_type_0}'"
                )
            return chunking_strategy_type_0
            return cast(Literal["by_title"] | None | Unset, data)

        chunking_strategy = _parse_chunking_strategy(d.pop("chunking_strategy", UNSET))

        def _parse_combine_under_n_chars(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        combine_under_n_chars = _parse_combine_under_n_chars(d.pop("combine_under_n_chars", UNSET))

        def _parse_coordinates(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        coordinates = _parse_coordinates(d.pop("coordinates", UNSET))

        def _parse_encoding(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        encoding = _parse_encoding(d.pop("encoding", UNSET))

        def _parse_extract_image_block_types(data: object) -> list[str] | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                extract_image_block_types_type_0 = cast(list[str], data)

                return extract_image_block_types_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(list[str] | None | Unset, data)

        extract_image_block_types = _parse_extract_image_block_types(d.pop("extract_image_block_types", UNSET))

        def _parse_gz_uncompressed_content_type(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        gz_uncompressed_content_type = _parse_gz_uncompressed_content_type(d.pop("gz_uncompressed_content_type", UNSET))

        def _parse_hi_res_model_name(data: object) -> None | PartitionParametersParamsHiResModelNameType0 | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                hi_res_model_name_type_0 = PartitionParametersParamsHiResModelNameType0(data)

                return hi_res_model_name_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | PartitionParametersParamsHiResModelNameType0 | Unset, data)

        hi_res_model_name = _parse_hi_res_model_name(d.pop("hi_res_model_name", UNSET))

        def _parse_include_page_breaks(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        include_page_breaks = _parse_include_page_breaks(d.pop("include_page_breaks", UNSET))

        def _parse_languages(data: object) -> list[str] | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                languages_type_0 = cast(list[str], data)

                return languages_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(list[str] | None | Unset, data)

        languages = _parse_languages(d.pop("languages", UNSET))

        def _parse_max_characters(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        max_characters = _parse_max_characters(d.pop("max_characters", UNSET))

        def _parse_multipage_sections(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        multipage_sections = _parse_multipage_sections(d.pop("multipage_sections", UNSET))

        def _parse_new_after_n_chars(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        new_after_n_chars = _parse_new_after_n_chars(d.pop("new_after_n_chars", UNSET))

        def _parse_output_format(data: object) -> None | str | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(None | str | Unset, data)

        output_format = _parse_output_format(d.pop("output_format", UNSET))

        def _parse_overlap(data: object) -> int | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(int | None | Unset, data)

        overlap = _parse_overlap(d.pop("overlap", UNSET))

        def _parse_overlap_all(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        overlap_all = _parse_overlap_all(d.pop("overlap_all", UNSET))

        def _parse_pdf_infer_table_structure(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        pdf_infer_table_structure = _parse_pdf_infer_table_structure(d.pop("pdf_infer_table_structure", UNSET))

        def _parse_skip_infer_table_types(data: object) -> list[str] | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, list):
                    raise TypeError()
                skip_infer_table_types_type_0 = cast(list[str], data)

                return skip_infer_table_types_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(list[str] | None | Unset, data)

        skip_infer_table_types = _parse_skip_infer_table_types(d.pop("skip_infer_table_types", UNSET))

        def _parse_split_pdf_page(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        split_pdf_page = _parse_split_pdf_page(d.pop("split_pdf_page", UNSET))

        def _parse_strategy(data: object) -> None | PartitionParametersParamsStrategyType0 | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            try:
                if not isinstance(data, str):
                    raise TypeError()
                strategy_type_0 = PartitionParametersParamsStrategyType0(data)

                return strategy_type_0
            except (TypeError, ValueError, AttributeError, KeyError):
                pass
            return cast(None | PartitionParametersParamsStrategyType0 | Unset, data)

        strategy = _parse_strategy(d.pop("strategy", UNSET))

        def _parse_xml_keep_tags(data: object) -> bool | None | Unset:
            if data is None:
                return data
            if isinstance(data, Unset):
                return data
            return cast(bool | None | Unset, data)

        xml_keep_tags = _parse_xml_keep_tags(d.pop("xml_keep_tags", UNSET))

        partition_parameters_params = cls(
            chunking_strategy=chunking_strategy,
            combine_under_n_chars=combine_under_n_chars,
            coordinates=coordinates,
            encoding=encoding,
            extract_image_block_types=extract_image_block_types,
            gz_uncompressed_content_type=gz_uncompressed_content_type,
            hi_res_model_name=hi_res_model_name,
            include_page_breaks=include_page_breaks,
            languages=languages,
            max_characters=max_characters,
            multipage_sections=multipage_sections,
            new_after_n_chars=new_after_n_chars,
            output_format=output_format,
            overlap=overlap,
            overlap_all=overlap_all,
            pdf_infer_table_structure=pdf_infer_table_structure,
            skip_infer_table_types=skip_infer_table_types,
            split_pdf_page=split_pdf_page,
            strategy=strategy,
            xml_keep_tags=xml_keep_tags,
        )

        partition_parameters_params.additional_properties = d
        return partition_parameters_params

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
