# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from unicourt.model.norm_corporate_group import NormCorporateGroup
from unicourt.model.norm_organization_ticker_array_inner import NormOrganizationTickerArrayInner
from unicourt.model.sos_data import SOSData
from typing import Optional, Set
from typing_extensions import Self

class NormOrganization(BaseModel):
    """
    NormOrganization
    """ # noqa: E501
    object: Optional[Annotated[str, Field(strict=True, max_length=16)]] = 'NormOrganization'
    norm_organization_id: Optional[Annotated[str, Field(min_length=18, strict=True, max_length=18)]] = Field(default=None, alias="normOrganizationId")
    name: Optional[Annotated[str, Field(strict=True, max_length=500)]] = None
    organization_type: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, alias="organizationType")
    lei: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    cik: Optional[Annotated[str, Field(strict=True, max_length=15)]] = None
    ticker_array: Optional[List[NormOrganizationTickerArrayInner]] = Field(default=None, alias="tickerArray")
    naics: Optional[Annotated[str, Field(strict=True, max_length=250)]] = None
    naics_description: Optional[Annotated[str, Field(strict=True, max_length=250)]] = Field(default=None, alias="naicsDescription")
    sic: Optional[Annotated[str, Field(strict=True, max_length=10)]] = None
    sic_description: Optional[Annotated[str, Field(strict=True, max_length=100)]] = Field(default=None, alias="sicDescription")
    is_involved_in_litigation: Optional[StrictBool] = Field(default=None, alias="isInvolvedInLitigation")
    norm_party_api: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, alias="normPartyAPI")
    norm_corporate_group_array: Optional[List[NormCorporateGroup]] = Field(default=None, alias="normCorporateGroupArray")
    sos_data_array: Optional[List[SOSData]] = Field(default=None, alias="sosDataArray")
    __properties: ClassVar[List[str]] = ["object", "normOrganizationId", "name", "organizationType", "lei", "cik", "tickerArray", "naics", "naicsDescription", "sic", "sicDescription", "isInvolvedInLitigation", "normPartyAPI", "normCorporateGroupArray", "sosDataArray"]

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

        if value not in set(['Business', 'GovernmentAgency']):
            raise ValueError("must be one of enum values ('Business', 'GovernmentAgency')")
        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 NormOrganization 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 ticker_array (list)
        _items = []
        if self.ticker_array:
            for _item in self.ticker_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['tickerArray'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in norm_corporate_group_array (list)
        _items = []
        if self.norm_corporate_group_array:
            for _item in self.norm_corporate_group_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['normCorporateGroupArray'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in sos_data_array (list)
        _items = []
        if self.sos_data_array:
            for _item in self.sos_data_array:
                if _item:
                    _items.append(_item.to_dict())
            _dict['sosDataArray'] = _items
        # set to None if lei (nullable) is None
        # and model_fields_set contains the field
        if self.lei is None and "lei" in self.model_fields_set:
            _dict['lei'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of NormOrganization 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 'NormOrganization',
            "normOrganizationId": obj.get("normOrganizationId"),
            "name": obj.get("name"),
            "organizationType": obj.get("organizationType"),
            "lei": obj.get("lei"),
            "cik": obj.get("cik"),
            "tickerArray": [NormOrganizationTickerArrayInner.from_dict(_item) for _item in obj["tickerArray"]] if obj.get("tickerArray") is not None else None,
            "naics": obj.get("naics"),
            "naicsDescription": obj.get("naicsDescription"),
            "sic": obj.get("sic"),
            "sicDescription": obj.get("sicDescription"),
            "isInvolvedInLitigation": obj.get("isInvolvedInLitigation"),
            "normPartyAPI": obj.get("normPartyAPI"),
            "normCorporateGroupArray": [NormCorporateGroup.from_dict(_item) for _item in obj["normCorporateGroupArray"]] if obj.get("normCorporateGroupArray") is not None else None,
            "sosDataArray": [SOSData.from_dict(_item) for _item in obj["sosDataArray"]] if obj.get("sosDataArray") is not None else None
        })
        return _obj


