# coding: utf-8

"""
    UniCourt Enterprise APIs

    <button><a href=\"/developers/enterpriseapi/api/download/UniCourt-Enterprise-API-Spec.yaml\" >Download UniCourt Enterprise APIs Specification</a></button> 

    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, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from unicourt.model.preview_document import PreviewDocument
from typing import Optional, Set
from typing_extensions import Self

class CaseDocument(BaseModel):
    """
    CaseDocument
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=12, strict=True, max_length=12)]] = Field(default='CaseDocument', description="Name of the object")
    case_document_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, description="UniCourt's Case Document ID.", alias="caseDocumentId")
    sort_order: Optional[StrictInt] = Field(default=None, description="Order of documents how it is being stored in UniCourt.", alias="sortOrder")
    name: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Document name.")
    description: Optional[StrictStr] = Field(default=None, description="Description of the document.")
    document_filed_date: Optional[Annotated[str, Field(min_length=25, strict=True, max_length=25)]] = Field(default=None, description="Document Date when it was filed. The document date will be either explicitly provided byt the court or if the document is associatated to a docket entry then the document date will be of docket entry date.", alias="documentFiledDate")
    parent_document_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, description="Document ID which is the parent document for the current document. This will be null if the current document is a parent document.", alias="parentDocumentId")
    child_document_id_array: Optional[List[Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]]]] = Field(default=None, description="List of child document ID's if exists or else it will be an empty lsit.", alias="childDocumentIdArray")
    pages: Optional[StrictInt] = Field(default=None, description="Total number of pages in the document.")
    is_preview_available: Optional[StrictBool] = Field(default=None, description="Determines if a preview is available for the case document.", alias="isPreviewAvailable")
    preview_document: Optional[PreviewDocument] = Field(default=None, alias="previewDocument")
    price: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Price of the document.")
    in_library: Optional[StrictBool] = Field(default=None, description="Determines if the document is present in the UniCourt Library or not.", alias="inLibrary")
    added_to_library_date: Optional[Annotated[str, Field(min_length=25, strict=True, max_length=25)]] = Field(default=None, description="Date and time when the document was downloaded and added to the UniCourt Crowd Source Library.", alias="addedToLibraryDate")
    estimated_order_duration: Optional[Annotated[str, Field(min_length=10, strict=True, max_length=25)]] = Field(default='estimateUnavailable', description="Estimated duration of a Order.", alias="estimatedOrderDuration")
    download_api: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Link to either view the document if it is downloaded and already present in the UniCourt CrowdSourced Library.", alias="downloadAPI")
    first_fetch_date: Optional[Annotated[str, Field(min_length=25, strict=True, max_length=25)]] = Field(default=None, description="Is the date when the document was first fetched from the court site.", alias="firstFetchDate")
    source_data_status: Optional[StrictStr] = Field(default=None, description="The status of source data of document. If the value of sourceDataStatus is SOURCE_DEPRECATED then it means that the Document has been migrated from old court site to a new court site and the data being shown in the API response is from a old court site. If the sourceDataStatus is NO_LONGER_AVAILABLE_IN_COURT then it means that a particular case is invalid in the court site.", alias="sourceDataStatus")
    __properties: ClassVar[List[str]] = ["object", "caseDocumentId", "sortOrder", "name", "description", "documentFiledDate", "parentDocumentId", "childDocumentIdArray", "pages", "isPreviewAvailable", "previewDocument", "price", "inLibrary", "addedToLibraryDate", "estimatedOrderDuration", "downloadAPI", "firstFetchDate", "sourceDataStatus"]

    @field_validator('estimated_order_duration')
    def estimated_order_duration_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['estimateUnavailable', 'withinMinutes', 'withinHours', 'withinDays', 'withinWeeks']):
            raise ValueError("must be one of enum values ('estimateUnavailable', 'withinMinutes', 'withinHours', 'withinDays', 'withinWeeks')")
        return value

    @field_validator('source_data_status')
    def source_data_status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['NO_LONGER_AVAILABLE_IN_COURT', 'SEALED', 'null']):
            raise ValueError("must be one of enum values ('NO_LONGER_AVAILABLE_IN_COURT', 'SEALED', 'null')")
        return value

    model_config = ConfigDict(
        populate_by_name=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"""
        # 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) -> Optional[Self]:
        """Create an instance of CaseDocument 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 preview_document
        if self.preview_document:
            _dict['previewDocument'] = self.preview_document.to_dict()
        # set to None if sort_order (nullable) is None
        # and model_fields_set contains the field
        if self.sort_order is None and "sort_order" in self.model_fields_set:
            _dict['sortOrder'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "object": obj.get("object") if obj.get("object") is not None else 'CaseDocument',
            "caseDocumentId": obj.get("caseDocumentId"),
            "sortOrder": obj.get("sortOrder"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "documentFiledDate": obj.get("documentFiledDate"),
            "parentDocumentId": obj.get("parentDocumentId"),
            "childDocumentIdArray": obj.get("childDocumentIdArray"),
            "pages": obj.get("pages"),
            "isPreviewAvailable": obj.get("isPreviewAvailable"),
            "previewDocument": PreviewDocument.from_dict(obj["previewDocument"]) if obj.get("previewDocument") is not None else None,
            "price": obj.get("price"),
            "inLibrary": obj.get("inLibrary"),
            "addedToLibraryDate": obj.get("addedToLibraryDate"),
            "estimatedOrderDuration": obj.get("estimatedOrderDuration") if obj.get("estimatedOrderDuration") is not None else 'estimateUnavailable',
            "downloadAPI": obj.get("downloadAPI"),
            "firstFetchDate": obj.get("firstFetchDate"),
            "sourceDataStatus": obj.get("sourceDataStatus")
        })
        return _obj


