# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.docket_entry_primary_documents import DocketEntryPrimaryDocuments
from unicourt.model.docket_entry_secondary_documents import DocketEntrySecondaryDocuments
from unicourt.model.referenced_docket_number import ReferencedDocketNumber
from unicourt.model.source_structured_data import SourceStructuredData
from typing import Optional, Set
from typing_extensions import Self

class DocketEntry(BaseModel):
    """
    DocketEntry
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=11, strict=True, max_length=11)]] = Field(default='DocketEntry', description="Name of the object")
    sort_order: Optional[StrictInt] = Field(default=None, description="Order number how the dockets have stored in UniCourt.", alias="sortOrder")
    docket_entry_date: Optional[datetime] = Field(default=None, description="Docket Action Date", alias="docketEntryDate")
    docket_number: Optional[StrictInt] = Field(default=None, description="The respective docket entry number which is defined in the court website.", alias="docketNumber")
    docket_badge: Optional[StrictStr] = Field(default=None, description="Docket Badge helps you to know what type of a docket entry it is.", alias="docketBadge")
    text: Optional[StrictStr] = Field(default=None, description="Source Docket Entry")
    text_structured: Optional[SourceStructuredData] = Field(default=None, alias="textStructured")
    referenced_docket_number_array: Optional[List[ReferencedDocketNumber]] = Field(default=None, description="Other Docket Numbers that referenced for a particular docket entry.", alias="referencedDocketNumberArray")
    docket_entry_primary_documents: Optional[DocketEntryPrimaryDocuments] = Field(default=None, alias="docketEntryPrimaryDocuments")
    docket_entry_secondary_documents: Optional[DocketEntrySecondaryDocuments] = Field(default=None, alias="docketEntrySecondaryDocuments")
    last_fetch_date: Optional[Annotated[str, Field(min_length=25, strict=True, max_length=25)]] = Field(default=None, description="When this docket entry was last fetched from the source.", alias="lastFetchDate")
    boundary: Optional[StrictStr] = Field(default=None, description="Determines if it is the first docket entry or the last docket entry. This value will be set only for the first and last docket entry. For other docket entries it will be null. However, this will be set as single_docket_entry when the Case contains only one docket entry.")
    __properties: ClassVar[List[str]] = ["object", "sortOrder", "docketEntryDate", "docketNumber", "docketBadge", "text", "textStructured", "referencedDocketNumberArray", "docketEntryPrimaryDocuments", "docketEntrySecondaryDocuments", "lastFetchDate", "boundary"]

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

        if value not in set(['DOCKET', 'CHARGE', 'HEARING', 'JUDGEMENT', 'FINANCIAL', 'DISPOSITION', 'SENTENCE', 'BOND', 'BAIL', 'CAUSE_OF_ACTION', 'ARREST', 'WARRANT', 'SUMMON', 'TICKLER', 'OPINION']):
            raise ValueError("must be one of enum values ('DOCKET', 'CHARGE', 'HEARING', 'JUDGEMENT', 'FINANCIAL', 'DISPOSITION', 'SENTENCE', 'BOND', 'BAIL', 'CAUSE_OF_ACTION', 'ARREST', 'WARRANT', 'SUMMON', 'TICKLER', 'OPINION')")
        return value

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

        if value not in set(['first', 'last', 'single_docket_entry', 'null']):
            raise ValueError("must be one of enum values ('first', 'last', 'single_docket_entry', '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 DocketEntry 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 text_structured
        if self.text_structured:
            _dict['textStructured'] = self.text_structured.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in referenced_docket_number_array (list)
        _items = []
        if self.referenced_docket_number_array:
            for _item in self.referenced_docket_number_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['referencedDocketNumberArray'] = _items
        # override the default output from pydantic by calling `to_dict()` of docket_entry_primary_documents
        if self.docket_entry_primary_documents:
            _dict['docketEntryPrimaryDocuments'] = self.docket_entry_primary_documents.to_dict()
        # override the default output from pydantic by calling `to_dict()` of docket_entry_secondary_documents
        if self.docket_entry_secondary_documents:
            _dict['docketEntrySecondaryDocuments'] = self.docket_entry_secondary_documents.to_dict()
        # set to None if docket_number (nullable) is None
        # and model_fields_set contains the field
        if self.docket_number is None and "docket_number" in self.model_fields_set:
            _dict['docketNumber'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of DocketEntry 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 'DocketEntry',
            "sortOrder": obj.get("sortOrder"),
            "docketEntryDate": obj.get("docketEntryDate"),
            "docketNumber": obj.get("docketNumber"),
            "docketBadge": obj.get("docketBadge"),
            "text": obj.get("text"),
            "textStructured": SourceStructuredData.from_dict(obj["textStructured"]) if obj.get("textStructured") is not None else None,
            "referencedDocketNumberArray": [ReferencedDocketNumber.from_dict(_item) for _item in obj["referencedDocketNumberArray"]] if obj.get("referencedDocketNumberArray") is not None else None,
            "docketEntryPrimaryDocuments": DocketEntryPrimaryDocuments.from_dict(obj["docketEntryPrimaryDocuments"]) if obj.get("docketEntryPrimaryDocuments") is not None else None,
            "docketEntrySecondaryDocuments": DocketEntrySecondaryDocuments.from_dict(obj["docketEntrySecondaryDocuments"]) if obj.get("docketEntrySecondaryDocuments") is not None else None,
            "lastFetchDate": obj.get("lastFetchDate"),
            "boundary": obj.get("boundary")
        })
        return _obj


