# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.source_charge_additional_data import SourceChargeAdditionalData
from typing import Optional, Set
from typing_extensions import Self

class SourceCharge(BaseModel):
    """
    Source charge data from the source site.
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=12, strict=True, max_length=12)]] = Field(default='SourceCharge', description="Name of the object")
    source_charge_raw: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Raw charge data from the source site.", alias="sourceChargeRaw")
    source_charge: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Charge data from the source site.", alias="sourceCharge")
    is_visible: Optional[StrictBool] = Field(default=None, description="Signifies if the charge is currently isVisible or not for the case.", alias="isVisible")
    source_statute: Optional[Annotated[str, Field(strict=True, max_length=50)]] = Field(default=None, description="Statute of a charge.", alias="sourceStatute")
    source_charge_degree: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Charge degree data from the source site.", alias="sourceChargeDegree")
    source_charge_severity: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="Charge severity data from the source site.", alias="sourceChargeSeverity")
    source_charge_additional_data_array: Optional[List[SourceChargeAdditionalData]] = Field(default=None, description="Additional data related to the charge which is available in the source site.", alias="sourceChargeAdditionalDataArray")
    first_fetch_date: Optional[Annotated[str, Field(min_length=25, strict=True, max_length=25)]] = Field(default=None, description="When this charge was first fetched from the court site.", alias="firstFetchDate")
    last_fetch_date: Optional[Annotated[str, Field(min_length=25, strict=True, max_length=25)]] = Field(default=None, description="When this charge was last fetched from the court site.", alias="lastFetchDate")
    __properties: ClassVar[List[str]] = ["object", "sourceChargeRaw", "sourceCharge", "isVisible", "sourceStatute", "sourceChargeDegree", "sourceChargeSeverity", "sourceChargeAdditionalDataArray", "firstFetchDate", "lastFetchDate"]

    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 SourceCharge 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 each item in source_charge_additional_data_array (list)
        _items = []
        if self.source_charge_additional_data_array:
            for _item in self.source_charge_additional_data_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['sourceChargeAdditionalDataArray'] = _items
        # set to None if source_charge (nullable) is None
        # and model_fields_set contains the field
        if self.source_charge is None and "source_charge" in self.model_fields_set:
            _dict['sourceCharge'] = None

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SourceCharge 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 'SourceCharge',
            "sourceChargeRaw": obj.get("sourceChargeRaw"),
            "sourceCharge": obj.get("sourceCharge"),
            "isVisible": obj.get("isVisible"),
            "sourceStatute": obj.get("sourceStatute"),
            "sourceChargeDegree": obj.get("sourceChargeDegree"),
            "sourceChargeSeverity": obj.get("sourceChargeSeverity"),
            "sourceChargeAdditionalDataArray": [SourceChargeAdditionalData.from_dict(_item) for _item in obj["sourceChargeAdditionalDataArray"]] if obj.get("sourceChargeAdditionalDataArray") is not None else None,
            "firstFetchDate": obj.get("firstFetchDate"),
            "lastFetchDate": obj.get("lastFetchDate")
        })
        return _obj


