# 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, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class Address(BaseModel):
    """
    Address object Data Schema
    """ # noqa: E501
    object: Optional[Annotated[str, Field(min_length=7, strict=True, max_length=7)]] = 'Address'
    street_address1: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=250)]] = Field(default=None, description="1st part of the street address.", alias="streetAddress1")
    street_address2: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=150)]] = Field(default=None, description="2nd part of the street address.", alias="streetAddress2")
    city: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=100)]] = Field(default=None, description="City")
    state_name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=100)]] = Field(default='UNKNOWN', description="State Name if present else default value.", alias="stateName")
    state_code: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=2)]] = Field(default=None, description="State Code if the state is a US state else contains null.", alias="stateCode")
    country_name: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=100)]] = Field(default='UNKNOWN', description="Country Name if present else default value.", alias="countryName")
    country_code: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=3)]] = Field(default=None, description="ISO 3166-1 alpha-3 (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Officially_assigned_code_elements). Code of the country if country name is present.", alias="countryCode")
    zip: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=10)]] = Field(default=None, description="Zip code of the address.")
    zip4: Optional[Annotated[str, Field(min_length=4, strict=True, max_length=4)]] = Field(default=None, description="4 digit extension of the zip code if the address is a US address.")
    is_visible: Optional[StrictBool] = Field(default=None, description="Boolean indicating if the address is visible or not.", alias="isVisible")
    first_fetch_date: Optional[datetime] = Field(default=None, description="Date at which this record is created in UniCourt.", alias="firstFetchDate")
    last_fetch_date: Optional[datetime] = Field(default=None, description="Date at which this record was updated in UniCourt.", alias="lastFetchDate")
    latitude: Optional[Union[Annotated[float, Field(le=90, strict=True, ge=-90)], Annotated[int, Field(le=90, strict=True, ge=-90)]]] = Field(default=None, description="Coordinates at geographic coordinate system.")
    longitude: Optional[Union[Annotated[float, Field(le=180, strict=True, ge=-180)], Annotated[int, Field(le=180, strict=True, ge=-180)]]] = Field(default=None, description="Coordinates at geographic coordinate system.")
    __properties: ClassVar[List[str]] = ["object", "streetAddress1", "streetAddress2", "city", "stateName", "stateCode", "countryName", "countryCode", "zip", "zip4", "isVisible", "firstFetchDate", "lastFetchDate", "latitude", "longitude"]

    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 Address 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 street_address1 (nullable) is None
        # and model_fields_set contains the field
        if self.street_address1 is None and "street_address1" in self.model_fields_set:
            _dict['streetAddress1'] = None

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Address 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 'Address',
            "streetAddress1": obj.get("streetAddress1"),
            "streetAddress2": obj.get("streetAddress2"),
            "city": obj.get("city"),
            "stateName": obj.get("stateName") if obj.get("stateName") is not None else 'UNKNOWN',
            "stateCode": obj.get("stateCode"),
            "countryName": obj.get("countryName") if obj.get("countryName") is not None else 'UNKNOWN',
            "countryCode": obj.get("countryCode"),
            "zip": obj.get("zip"),
            "zip4": obj.get("zip4"),
            "isVisible": obj.get("isVisible"),
            "firstFetchDate": obj.get("firstFetchDate"),
            "lastFetchDate": obj.get("lastFetchDate"),
            "latitude": obj.get("latitude"),
            "longitude": obj.get("longitude")
        })
        return _obj


