# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class ChunkedDocumentResultItem(BaseModel):
    """
    A single chunk of a document with its metadata and content.
    """ # noqa: E501
    filename: StrictStr
    chunk_index: StrictInt
    text: StrictStr = Field(description="The chunk text with structural context (headers, formatting)")
    raw_text: Optional[StrictStr] = None
    num_tokens: Optional[StrictInt] = None
    headings: Optional[List[StrictStr]] = None
    captions: Optional[List[StrictStr]] = None
    doc_items: List[StrictStr] = Field(description="List of doc items references")
    page_numbers: Optional[List[StrictInt]] = None
    metadata: Optional[Dict[str, Any]] = None
    __properties: ClassVar[List[str]] = ["filename", "chunk_index", "text", "raw_text", "num_tokens", "headings", "captions", "doc_items", "page_numbers", "metadata"]

    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 ChunkedDocumentResultItem 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,
        )
        # set to None if raw_text (nullable) is None
        # and model_fields_set contains the field
        if self.raw_text is None and "raw_text" in self.model_fields_set:
            _dict['raw_text'] = None

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "filename": obj.get("filename"),
            "chunk_index": obj.get("chunk_index"),
            "text": obj.get("text"),
            "raw_text": obj.get("raw_text"),
            "num_tokens": obj.get("num_tokens"),
            "headings": obj.get("headings"),
            "captions": obj.get("captions"),
            "doc_items": obj.get("doc_items"),
            "page_numbers": obj.get("page_numbers"),
            "metadata": obj.get("metadata")
        })
        return _obj


