# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ...core.datetime_utils import serialize_datetime
from ...core.pydantic_utilities import deep_union_pydantic_dicts, pydantic_v1
from ...generated_types.types.attributes import Attributes
from ...generated_types.types.country import Country
from ...generated_types.types.entities import Entities
from .identifier import Identifier
from .relationship_count import RelationshipCount
from .source_count_info import SourceCountInfo


class EmbeddedEntity(pydantic_v1.BaseModel):
    """
    Fields of an entity when nested within other data structures.
    """

    id: str = pydantic_v1.Field()
    """
    Unique identifier of the entity
    """

    label: str = pydantic_v1.Field()
    """
    Display name of the entity
    """

    degree: int = pydantic_v1.Field()
    """
    Number of outgoing relationships
    """

    closed: bool = pydantic_v1.Field()
    """
    True if the entity existed in the past but not at the present time, otherwise false. Always false for data curation.
    """

    entity_url: str = pydantic_v1.Field()
    """
    Convenience URL to the entity in the API.
    """

    pep: bool = pydantic_v1.Field()
    """
    True if the entity has the ["Politically Exposed Person (PEP)" risk factor](/sayari-library/ontology/risk-factors#politically-exposed-person-pep-), otherwise false.
    """

    psa_id: typing.Optional[str] = None
    psa_count: int = pydantic_v1.Field()
    """
    Number of entities that are Possibly the Same As (PSA) the entity.
    """

    sanctioned: bool = pydantic_v1.Field()
    """
    True if the entity has the ["Sanctioned" risk factor](/sayari-library/ontology/risk-factors#sanctioned), otherwise false.
    """

    type: Entities = pydantic_v1.Field()
    """
    The [entity type](/sayari-library/ontology/entities).
    """

    identifiers: typing.List[Identifier]
    countries: typing.List[Country] = pydantic_v1.Field()
    """
    Entity [country](/sayari-library/ontology/enumerated-types#country)
    """

    source_count: typing.Dict[str, SourceCountInfo] = pydantic_v1.Field()
    """
    Number of records associated with the entity, grouped by source.
    """

    addresses: typing.List[str] = pydantic_v1.Field()
    """
    List of physical addresses associated with the entity. See more [here](/sayari-library/ontology/attributes#address)
    """

    trade_count: typing.Dict[str, int]
    date_of_birth: typing.Optional[str] = pydantic_v1.Field(default=None)
    """
    Birth date of a person. See more [here](/sayari-library/ontology/attributes#date-of-birth)
    """

    relationship_count: RelationshipCount
    user_relationship_count: RelationshipCount
    attribute_count: typing.Dict[Attributes, int] = pydantic_v1.Field()
    """
    Count of attributes for a given [attribute type](/sayari-library/ontology/attributes)
    """

    user_attribute_count: typing.Dict[Attributes, int] = pydantic_v1.Field()
    """
    Count of user-created attributes for a given [attribute type](/sayari-library/ontology/attributes)
    """

    related_entities_count: int
    user_related_entities_count: int
    user_record_count: int
    reference_id: typing.Optional[str] = None

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs}

        return deep_union_pydantic_dicts(
            super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none)
        )

    class Config:
        frozen = True
        smart_union = True
        extra = pydantic_v1.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
