# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.case_status import CaseStatus
from unicourt.model.case_type import CaseType
from unicourt.model.court import Court
from unicourt.model.court_location import CourtLocation
from unicourt.model.matched_object import MatchedObject
from typing import Optional, Set
from typing_extensions import Self

class CaseSearchResult(BaseModel):
    """
    CaseSearchResult
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=16, strict=True, max_length=16)]] = 'CaseSearchResult'
    case_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, alias="caseId")
    case_name: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, alias="caseName")
    case_number: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(default=None, alias="caseNumber")
    filed_date: Optional[datetime] = Field(default=None, alias="filedDate")
    court: Optional[Court] = None
    court_location: Optional[CourtLocation] = Field(default=None, alias="courtLocation")
    case_type: Optional[CaseType] = Field(default=None, alias="caseType")
    case_status: Optional[CaseStatus] = Field(default=None, alias="caseStatus")
    first_fetch_date: Optional[datetime] = Field(default=None, alias="firstFetchDate")
    last_fetch_date: Optional[datetime] = Field(default=None, alias="lastFetchDate")
    last_fetch_date_with_updates: Optional[datetime] = Field(default=None, alias="lastFetchDateWithUpdates")
    participants_last_fetch_date: Optional[datetime] = Field(default=None, alias="participantsLastFetchDate")
    case_api: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(default=None, alias="caseAPI")
    matched_object_array: Optional[List[MatchedObject]] = Field(default=None, alias="matchedObjectArray")
    __properties: ClassVar[List[str]] = ["object", "caseId", "caseName", "caseNumber", "filedDate", "court", "courtLocation", "caseType", "caseStatus", "firstFetchDate", "lastFetchDate", "lastFetchDateWithUpdates", "participantsLastFetchDate", "caseAPI", "matchedObjectArray"]

    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 CaseSearchResult 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 court
        if self.court:
            _dict['court'] = self.court.to_dict()
        # override the default output from pydantic by calling `to_dict()` of court_location
        if self.court_location:
            _dict['courtLocation'] = self.court_location.to_dict()
        # override the default output from pydantic by calling `to_dict()` of case_type
        if self.case_type:
            _dict['caseType'] = self.case_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of case_status
        if self.case_status:
            _dict['caseStatus'] = self.case_status.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in matched_object_array (list)
        _items = []
        if self.matched_object_array:
            for _item in self.matched_object_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['matchedObjectArray'] = _items
        # set to None if case_name (nullable) is None
        # and model_fields_set contains the field
        if self.case_name is None and "case_name" in self.model_fields_set:
            _dict['caseName'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CaseSearchResult 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 'CaseSearchResult',
            "caseId": obj.get("caseId"),
            "caseName": obj.get("caseName"),
            "caseNumber": obj.get("caseNumber"),
            "filedDate": obj.get("filedDate"),
            "court": Court.from_dict(obj["court"]) if obj.get("court") is not None else None,
            "courtLocation": CourtLocation.from_dict(obj["courtLocation"]) if obj.get("courtLocation") is not None else None,
            "caseType": CaseType.from_dict(obj["caseType"]) if obj.get("caseType") is not None else None,
            "caseStatus": CaseStatus.from_dict(obj["caseStatus"]) if obj.get("caseStatus") is not None else None,
            "firstFetchDate": obj.get("firstFetchDate"),
            "lastFetchDate": obj.get("lastFetchDate"),
            "lastFetchDateWithUpdates": obj.get("lastFetchDateWithUpdates"),
            "participantsLastFetchDate": obj.get("participantsLastFetchDate"),
            "caseAPI": obj.get("caseAPI"),
            "matchedObjectArray": [MatchedObject.from_dict(_item) for _item in obj["matchedObjectArray"]] if obj.get("matchedObjectArray") is not None else None
        })
        return _obj


