# 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, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class ServiceHistory(BaseModel):
    """
    A timeline of courts where the judge has been employed.
    """ # noqa: E501
    object: Optional[Annotated[str, Field(strict=True, max_length=14)]] = 'ServiceHistory'
    appointed_by: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="The President-in-charge of the Judges appointment.", alias="appointedBy")
    reason_for_termination: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="The reason for the Judges termination for the current position.", alias="reasonForTermination")
    source_court: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, description="The court served by the Judge. The court is taken from source.", alias="sourceCourt")
    title: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="Title held by the Judge.")
    from_year: Optional[StrictInt] = Field(default=None, description="The year in which the Judge began practicing in his current service.", alias="fromYear")
    to_year: Optional[StrictInt] = Field(default=None, description="The year in which the Judge stoped practicing in his current service.", alias="toYear")
    from_date: Optional[datetime] = Field(default=None, description="The year in which the Judge began practicing in his current service.", alias="fromDate")
    to_date: Optional[datetime] = Field(default=None, description="The year in which the Judge stoped practicing in his current service.", alias="toDate")
    is_visible: Optional[StrictBool] = Field(default=None, description="Boolean indicating if the service history  is visible or not.", alias="isVisible")
    __properties: ClassVar[List[str]] = ["object", "appointedBy", "reasonForTermination", "sourceCourt", "title", "fromYear", "toYear", "fromDate", "toDate", "isVisible"]

    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 ServiceHistory 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,
        )
        # set to None if appointed_by (nullable) is None
        # and model_fields_set contains the field
        if self.appointed_by is None and "appointed_by" in self.model_fields_set:
            _dict['appointedBy'] = None

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ServiceHistory 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 'ServiceHistory',
            "appointedBy": obj.get("appointedBy"),
            "reasonForTermination": obj.get("reasonForTermination"),
            "sourceCourt": obj.get("sourceCourt"),
            "title": obj.get("title"),
            "fromYear": obj.get("fromYear"),
            "toYear": obj.get("toYear"),
            "fromDate": obj.get("fromDate"),
            "toDate": obj.get("toDate"),
            "isVisible": obj.get("isVisible")
        })
        return _obj


