# 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 import Case
from unicourt.model.case_update_pacer_options_response import CaseUpdatePacerOptionsResponse
from unicourt.model.last_tracked_details import LastTrackedDetails
from unicourt.model.schedule import Schedule
from typing import Optional, Set
from typing_extensions import Self

class CaseTrack(BaseModel):
    """
    CaseTrack
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=9, strict=True, max_length=9)]] = Field(default='CaseTrack', description="Name of the object.")
    case_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, description="Unique Id for a Case in UniCourt.", alias="caseId")
    pacer_options: Optional[CaseUpdatePacerOptionsResponse] = Field(default=None, alias="pacerOptions")
    schedule: Optional[Schedule] = None
    last_tracked_details: Optional[LastTrackedDetails] = Field(default=None, alias="lastTrackedDetails")
    last_fetch_date: Optional[datetime] = Field(default=None, description="The date and time when the case was last fetched from the Court. This date and time is in UTC. Formatted as YYYY-MM-DDTHH:MM:SS+ZZ:zz, Note: It is not necessary that every time the case is fetched from Court we find changes in the case information. It could be that we already have the latest information from the Court and no changes exist.", alias="lastFetchDate")
    last_fetch_date_with_updates: Optional[datetime] = Field(default=None, description="The date and time when the case was last fetched from the Court where we found changes in the case information. This date and time is in UTC. Formatted as YYYY-MM-DDTHH:MM:SS+ZZ:zz,", alias="lastFetchDateWithUpdates")
    case_api: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=255)]] = Field(default=None, alias="caseAPI")
    case: Optional[Case] = None
    __properties: ClassVar[List[str]] = ["object", "caseId", "pacerOptions", "schedule", "lastTrackedDetails", "lastFetchDate", "lastFetchDateWithUpdates", "caseAPI", "case"]

    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 CaseTrack 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 pacer_options
        if self.pacer_options:
            _dict['pacerOptions'] = self.pacer_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of schedule
        if self.schedule:
            _dict['schedule'] = self.schedule.to_dict()
        # override the default output from pydantic by calling `to_dict()` of last_tracked_details
        if self.last_tracked_details:
            _dict['lastTrackedDetails'] = self.last_tracked_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of case
        if self.case:
            _dict['case'] = self.case.to_dict()
        # set to None if last_fetch_date (nullable) is None
        # and model_fields_set contains the field
        if self.last_fetch_date is None and "last_fetch_date" in self.model_fields_set:
            _dict['lastFetchDate'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CaseTrack 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 'CaseTrack',
            "caseId": obj.get("caseId"),
            "pacerOptions": CaseUpdatePacerOptionsResponse.from_dict(obj["pacerOptions"]) if obj.get("pacerOptions") is not None else None,
            "schedule": Schedule.from_dict(obj["schedule"]) if obj.get("schedule") is not None else None,
            "lastTrackedDetails": LastTrackedDetails.from_dict(obj["lastTrackedDetails"]) if obj.get("lastTrackedDetails") is not None else None,
            "lastFetchDate": obj.get("lastFetchDate"),
            "lastFetchDateWithUpdates": obj.get("lastFetchDateWithUpdates"),
            "caseAPI": obj.get("caseAPI"),
            "case": Case.from_dict(obj["case"]) if obj.get("case") is not None else None
        })
        return _obj


