# 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
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.attorney_law_firm import AttorneyLawFirm
from unicourt.model.attorney_type import AttorneyType
from unicourt.model.contact import Contact
from unicourt.model.party_attorney_associations import PartyAttorneyAssociations
from unicourt.model.possible_norm_attorney import PossibleNormAttorney
from unicourt.model.possible_norm_law_firm import PossibleNormLawFirm
from typing import Optional, Set
from typing_extensions import Self

class Attorney(BaseModel):
    """
    Attorney
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=8, strict=True, max_length=8)]] = Field(default='Attorney', description="Name of the object")
    attorney_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, description="ID for the attorney in this case. This ID is unique within a case and NOT across cases. If the same attorney were to appear in another case this ID would be different.", alias="attorneyId")
    name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=250)]] = Field(default=None, description="Name of the attorney as provided by Court.")
    name_prefix: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, alias="namePrefix")
    first_name: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, description="First name of the attorney. This is normalized by UniCourt.", alias="firstName")
    middle_name: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="Middle name of the attorney. This is normalized by UniCourt.", alias="middleName")
    last_name: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, description="Last name of the attorney. This is normalized by UniCourt.", alias="lastName")
    name_suffix: Optional[Annotated[str, Field(strict=True, max_length=10)]] = Field(default=None, alias="nameSuffix")
    contact: Optional[Contact] = None
    attorney_law_firm_array: Optional[Annotated[List[AttorneyLawFirm], Field(max_length=25)]] = Field(default=None, alias="attorneyLawFirmArray")
    bar_number: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, description="The bar enrollment number of an attorney.", alias="barNumber")
    attorney_type: Optional[AttorneyType] = Field(default=None, alias="attorneyType")
    source_attorney_type: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, description="Attorney Type as provided by Court.", alias="sourceAttorneyType")
    is_visible: Optional[StrictBool] = Field(default=None, description="Signifies if the attorney as this attorney type is currently isVisible or not for the case.", alias="isVisible")
    first_fetch_date: Optional[datetime] = Field(default=None, description="When was the attorney first fetched from the court site.", alias="firstFetchDate")
    last_fetch_date: Optional[datetime] = Field(default=None, description="When was the attorney last fetched from the court site.", alias="lastFetchDate")
    party_attorney_associations: Optional[PartyAttorneyAssociations] = Field(default=None, alias="partyAttorneyAssociations")
    possible_norm_attorney_array: Optional[List[PossibleNormAttorney]] = Field(default=None, alias="possibleNormAttorneyArray")
    possible_norm_law_firm_array: Optional[List[PossibleNormLawFirm]] = Field(default=None, description="Possible Norm Lawfirm array for a Attorney.", alias="possibleNormLawFirmArray")
    party_role_group_id_array: Optional[List[Annotated[str, Field(min_length=18, strict=True, max_length=18)]]] = Field(default=None, description="Party Role Group Id for a Attorney.", alias="partyRoleGroupIdArray")
    party_role_id_array: Optional[List[Annotated[str, Field(min_length=18, strict=True, max_length=18)]]] = Field(default=None, description="Party Role Id for a Attorney.", alias="partyRoleIdArray")
    __properties: ClassVar[List[str]] = ["object", "attorneyId", "name", "namePrefix", "firstName", "middleName", "lastName", "nameSuffix", "contact", "attorneyLawFirmArray", "barNumber", "attorneyType", "sourceAttorneyType", "isVisible", "firstFetchDate", "lastFetchDate", "partyAttorneyAssociations", "possibleNormAttorneyArray", "possibleNormLawFirmArray", "partyRoleGroupIdArray", "partyRoleIdArray"]

    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 Attorney 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 contact
        if self.contact:
            _dict['contact'] = self.contact.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in attorney_law_firm_array (list)
        _items = []
        if self.attorney_law_firm_array:
            for _item in self.attorney_law_firm_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['attorneyLawFirmArray'] = _items
        # override the default output from pydantic by calling `to_dict()` of attorney_type
        if self.attorney_type:
            _dict['attorneyType'] = self.attorney_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of party_attorney_associations
        if self.party_attorney_associations:
            _dict['partyAttorneyAssociations'] = self.party_attorney_associations.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in possible_norm_attorney_array (list)
        _items = []
        if self.possible_norm_attorney_array:
            for _item in self.possible_norm_attorney_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['possibleNormAttorneyArray'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in possible_norm_law_firm_array (list)
        _items = []
        if self.possible_norm_law_firm_array:
            for _item in self.possible_norm_law_firm_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['possibleNormLawFirmArray'] = _items
        # set to None if name_prefix (nullable) is None
        # and model_fields_set contains the field
        if self.name_prefix is None and "name_prefix" in self.model_fields_set:
            _dict['namePrefix'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Attorney 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 'Attorney',
            "attorneyId": obj.get("attorneyId"),
            "name": obj.get("name"),
            "namePrefix": obj.get("namePrefix"),
            "firstName": obj.get("firstName"),
            "middleName": obj.get("middleName"),
            "lastName": obj.get("lastName"),
            "nameSuffix": obj.get("nameSuffix"),
            "contact": Contact.from_dict(obj["contact"]) if obj.get("contact") is not None else None,
            "attorneyLawFirmArray": [AttorneyLawFirm.from_dict(_item) for _item in obj["attorneyLawFirmArray"]] if obj.get("attorneyLawFirmArray") is not None else None,
            "barNumber": obj.get("barNumber"),
            "attorneyType": AttorneyType.from_dict(obj["attorneyType"]) if obj.get("attorneyType") is not None else None,
            "sourceAttorneyType": obj.get("sourceAttorneyType"),
            "isVisible": obj.get("isVisible"),
            "firstFetchDate": obj.get("firstFetchDate"),
            "lastFetchDate": obj.get("lastFetchDate"),
            "partyAttorneyAssociations": PartyAttorneyAssociations.from_dict(obj["partyAttorneyAssociations"]) if obj.get("partyAttorneyAssociations") is not None else None,
            "possibleNormAttorneyArray": [PossibleNormAttorney.from_dict(_item) for _item in obj["possibleNormAttorneyArray"]] if obj.get("possibleNormAttorneyArray") is not None else None,
            "possibleNormLawFirmArray": [PossibleNormLawFirm.from_dict(_item) for _item in obj["possibleNormLawFirmArray"]] if obj.get("possibleNormLawFirmArray") is not None else None,
            "partyRoleGroupIdArray": obj.get("partyRoleGroupIdArray"),
            "partyRoleIdArray": obj.get("partyRoleIdArray")
        })
        return _obj


