# coding: utf-8

"""
    AI Hub API

    The AI Hub REST API. See https://docs.instabase.com/api-sdk/ for more details.

    The version of the OpenAPI document: 0.1
    Contact: support@instabase.com
    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 typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictBool, StrictInt, StrictStr
from pydantic import Field
from aihub.models.document_field import DocumentField
from aihub.models.document_validations import DocumentValidations
from aihub.models.modification_object import ModificationObject
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class Document(BaseModel):
    """
    Document
    """ # noqa: E501
    fields: Optional[List[DocumentField]] = Field(default=None, description="A list containing the extracted fields from the document, each with its field name, extracted value, and type. See `<DOCUMENT-FIELD>` structure for details.")
    review_completed: Optional[StrictBool] = Field(default=None, description="Indicates whether the document has been marked as reviewed.")
    class_name: Optional[StrictStr] = Field(default=None, description="The classification label of the document. `null` if classification is not applicable.")
    post_processed_paths: Optional[List[StrictStr]] = Field(default=None, description="An array of strings, each representing a path to post-processed documents.")
    class_edit_history: Optional[List[ModificationObject]] = Field(default=None, description="An array containing the history of edits to the document class.")
    validations: Optional[DocumentValidations] = None
    doc_id: Optional[StrictInt] = Field(default=None, description="ID of document.")
    __properties: ClassVar[List[str]] = ["fields", "review_completed", "class_name", "post_processed_paths", "class_edit_history", "validations", "doc_id"]

    model_config = {
        "populate_by_name": True,
        "validate_assignment": True
    }


    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"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Create an instance of Document 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in fields (list)
        _items = []
        if self.fields:
            for _item in self.fields:
                if _item:
                    _items.append(_item.to_dict())
            _dict['fields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in class_edit_history (list)
        _items = []
        if self.class_edit_history:
            for _item in self.class_edit_history:
                if _item:
                    _items.append(_item.to_dict())
            _dict['class_edit_history'] = _items
        # override the default output from pydantic by calling `to_dict()` of validations
        if self.validations:
            _dict['validations'] = self.validations.to_dict()
        # set to None if class_name (nullable) is None
        # and model_fields_set contains the field
        if self.class_name is None and "class_name" in self.model_fields_set:
            _dict['class_name'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of Document from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "fields": [DocumentField.from_dict(_item) for _item in obj.get("fields")] if obj.get("fields") is not None else None,
            "review_completed": obj.get("review_completed"),
            "class_name": obj.get("class_name"),
            "post_processed_paths": obj.get("post_processed_paths"),
            "class_edit_history": [ModificationObject.from_dict(_item) for _item in obj.get("class_edit_history")] if obj.get("class_edit_history") is not None else None,
            "validations": DocumentValidations.from_dict(obj.get("validations")) if obj.get("validations") is not None else None,
            "doc_id": obj.get("doc_id")
        })
        return _obj


