# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.bar_source_data import BarSourceData
from unicourt.model.contact import Contact
from typing import Optional, Set
from typing_extensions import Self

class BarRecord(BaseModel):
    """
    This contains the Attorney details that is obtained from the State Bar where the attorney is registered.
    """ # noqa: E501
    object: Optional[Annotated[str, Field(strict=True, max_length=9)]] = 'BarRecord'
    bar_number: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, alias="barNumber")
    bar_source_type: Optional[Annotated[str, Field(strict=True, max_length=70)]] = Field(default=None, alias="barSourceType")
    admitted_date: Optional[datetime] = Field(default=None, description="The admittedDate is the date when an attorney was admitted to the bar of a given state.", alias="admittedDate")
    state_code: Optional[Annotated[str, Field(strict=True, max_length=2)]] = Field(default=None, alias="stateCode")
    status: Optional[Annotated[str, Field(strict=True, max_length=15)]] = None
    inactivation_date: Optional[datetime] = Field(default=None, alias="inactivationDate")
    bar_source_data: Optional[BarSourceData] = Field(default=None, alias="barSourceData")
    contact: Optional[Contact] = None
    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, description="Last Fetch Date of the Attorney Update.", alias="lastFetchDateWithUpdates")
    __properties: ClassVar[List[str]] = ["object", "barNumber", "barSourceType", "admittedDate", "stateCode", "status", "inactivationDate", "barSourceData", "contact", "firstFetchDate", "lastFetchDate", "lastFetchDateWithUpdates"]

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

        if value not in set(['Active', 'Inactive', 'Not Classified', 'Unknown']):
            raise ValueError("must be one of enum values ('Active', 'Inactive', 'Not Classified', 'Unknown')")
        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 BarRecord 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 bar_source_data
        if self.bar_source_data:
            _dict['barSourceData'] = self.bar_source_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of contact
        if self.contact:
            _dict['contact'] = self.contact.to_dict()
        # 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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BarRecord 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 'BarRecord',
            "barNumber": obj.get("barNumber"),
            "barSourceType": obj.get("barSourceType"),
            "admittedDate": obj.get("admittedDate"),
            "stateCode": obj.get("stateCode"),
            "status": obj.get("status"),
            "inactivationDate": obj.get("inactivationDate"),
            "barSourceData": BarSourceData.from_dict(obj["barSourceData"]) if obj.get("barSourceData") is not None else None,
            "contact": Contact.from_dict(obj["contact"]) if obj.get("contact") is not None else None,
            "firstFetchDate": obj.get("firstFetchDate"),
            "lastFetchDate": obj.get("lastFetchDate"),
            "lastFetchDateWithUpdates": obj.get("lastFetchDateWithUpdates")
        })
        return _obj


