"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from ascend_sdk import utils
from ascend_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from ascend_sdk.utils import validate_open_enum
from enum import Enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class PartyBusinessIndustrialClassification(str, Enum, metaclass=utils.OpenEnumMeta):
    BUSINESS_INDUSTRIAL_CLASSIFICATION_UNSPECIFIED = (
        "BUSINESS_INDUSTRIAL_CLASSIFICATION_UNSPECIFIED"
    )
    AGRICULTURE_FORESTRY_AND_FISHING = "AGRICULTURE_FORESTRY_AND_FISHING"
    MINING = "MINING"
    CONSTRUCTION = "CONSTRUCTION"
    MANUFACTURING = "MANUFACTURING"
    TRANSPORTATION_COMMUNICATIONS_ELECTRIC_GAS_AND_SANITARY_SERVICES = (
        "TRANSPORTATION_COMMUNICATIONS_ELECTRIC_GAS_AND_SANITARY_SERVICES"
    )
    WHOLESALE_TRADE = "WHOLESALE_TRADE"
    RETAIL_TRADE = "RETAIL_TRADE"
    FINANCE_INSURANCE_AND_REAL_ESTATE = "FINANCE_INSURANCE_AND_REAL_ESTATE"
    SERVICES = "SERVICES"
    PUBLIC_ADMINISTRATION = "PUBLIC_ADMINISTRATION"


class PartyCorporateStructure(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Corporate structure of the entity."""

    ENTITY_CORPORATE_STRUCTURE_UNSPECIFIED = "ENTITY_CORPORATE_STRUCTURE_UNSPECIFIED"
    CORPORATION_C_CORP = "CORPORATION_C_CORP"
    CORPORATION_S_CORP = "CORPORATION_S_CORP"
    CORPORATION_B_CORP = "CORPORATION_B_CORP"
    CORPORATION_NONPROFIT = "CORPORATION_NONPROFIT"


class PartyNegativeNewsTypedDict(TypedDict):
    r"""Information about any negative news against related parties and entities"""

    negative_news_against_related_parties: NotRequired[bool]
    r"""Indicates whether there is negative news against related parties"""
    negative_news_against_related_parties_description: NotRequired[str]
    r"""Description of the negative news against related parties"""


class PartyNegativeNews(BaseModel):
    r"""Information about any negative news against related parties and entities"""

    negative_news_against_related_parties: Optional[bool] = None
    r"""Indicates whether there is negative news against related parties"""

    negative_news_against_related_parties_description: Optional[str] = None
    r"""Description of the negative news against related parties"""


class PartyEntityDueDiligenceTypedDict(TypedDict):
    r"""Due Diligence for Legal Entities"""

    entity_issues_bearer_shares: NotRequired[bool]
    r"""Indicates whether the entity issues bearer shares"""
    negative_news: NotRequired[Nullable[PartyNegativeNewsTypedDict]]
    r"""Information about any negative news against related parties and entities"""


class PartyEntityDueDiligence(BaseModel):
    r"""Due Diligence for Legal Entities"""

    entity_issues_bearer_shares: Optional[bool] = None
    r"""Indicates whether the entity issues bearer shares"""

    negative_news: OptionalNullable[PartyNegativeNews] = UNSET
    r"""Information about any negative news against related parties and entities"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["entity_issues_bearer_shares", "negative_news"]
        nullable_fields = ["negative_news"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyEntityType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The entity type."""

    ENTITY_TYPE_UNSPECIFIED = "ENTITY_TYPE_UNSPECIFIED"
    CORPORATION = "CORPORATION"
    LIMITED_LIABILITY_COMPANY = "LIMITED_LIABILITY_COMPANY"
    PARTNERSHIP = "PARTNERSHIP"
    SOLE_PROPRIETORSHIP_OR_SINGLE_MEMBER_LLC = (
        "SOLE_PROPRIETORSHIP_OR_SINGLE_MEMBER_LLC"
    )
    TRUST = "TRUST"
    ESTATE = "ESTATE"


class PartyExemptCustomerReason(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The reason the customer is exempt from verifying beneficial owners, if applicable."""

    EXEMPT_REASON_UNSPECIFIED = "EXEMPT_REASON_UNSPECIFIED"
    REGULATED_FINANCIAL_INSTITUTION = "REGULATED_FINANCIAL_INSTITUTION"
    DEPARTMENT_OR_AGENCY_OF_FEDERAL_STATE_OR_SUBDIVISION = (
        "DEPARTMENT_OR_AGENCY_OF_FEDERAL_STATE_OR_SUBDIVISION"
    )
    NON_BANK_LISTED_ENTITY = "NON_BANK_LISTED_ENTITY"
    SECTION_12_SECURITIES_EXCHANGE_ACT_1934_OR_15_D = (
        "SECTION_12_SECURITIES_EXCHANGE_ACT_1934_OR_15D"
    )
    SECTION_3_INVESTMENT_COMPANY_ACT_1940 = "SECTION_3_INVESTMENT_COMPANY_ACT_1940"
    SECTION_202_A_INVESTMENT_ADVISORS_ACT_1940 = (
        "SECTION_202A_INVESTMENT_ADVISORS_ACT_1940"
    )
    SECTION_3_SECURITIES_EXCHANGE_ACT_1934_SECTION_6_OR_17_A = (
        "SECTION_3_SECURITIES_EXCHANGE_ACT_1934_SECTION_6_OR_17A"
    )
    ANY_OTHER_SECURITIES_EXCHANGE_ACT_1934 = "ANY_OTHER_SECURITIES_EXCHANGE_ACT_1934"
    COMMODITY_FUTURES_TRADING_COMMISSION_REGISTERED = (
        "COMMODITY_FUTURES_TRADING_COMMISSION_REGISTERED"
    )
    PUBLIC_ACCOUNTING_FIRM_SECTION_102_SARBANES_OXLEY = (
        "PUBLIC_ACCOUNTING_FIRM_SECTION_102_SARBANES_OXLEY"
    )
    STATE_REGULATED_INSURANCE_COMPANY = "STATE_REGULATED_INSURANCE_COMPANY"


class PartyFormationDateTypedDict(TypedDict):
    r"""If the legal entity is a trust, the formation date is required."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyFormationDate(BaseModel):
    r"""If the legal entity is a trust, the formation date is required."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyEffectiveDateTypedDict(TypedDict):
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyEffectiveDate(BaseModel):
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLargeTraderTypedDict(TypedDict):
    r"""Large trader for the legal entity."""

    effective_date: NotRequired[Nullable[PartyEffectiveDateTypedDict]]
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""
    large_trader_id: NotRequired[str]
    r"""SEC-issued ID signifying the person/entity as a large trader; Required for CAIS regulatory reporting."""


class PartyLargeTrader(BaseModel):
    r"""Large trader for the legal entity."""

    effective_date: OptionalNullable[PartyEffectiveDate] = UNSET
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""

    large_trader_id: Optional[str] = None
    r"""SEC-issued ID signifying the person/entity as a large trader; Required for CAIS regulatory reporting."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["effective_date", "large_trader_id"]
        nullable_fields = ["effective_date"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyLegalAddressTypedDict(TypedDict):
    r"""The mailing address of the legal entity. Required fields within the `legal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: NotRequired[List[str]]
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """
    administrative_area: NotRequired[str]
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""
    language_code: NotRequired[str]
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """
    locality: NotRequired[str]
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""
    organization: NotRequired[str]
    r"""Optional. The name of the organization at the address."""
    postal_code: NotRequired[str]
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""
    recipients: NotRequired[List[str]]
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""
    region_code: NotRequired[str]
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""
    revision: NotRequired[int]
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """
    sorting_code: NotRequired[str]
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""
    sublocality: NotRequired[str]
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyLegalAddress(BaseModel):
    r"""The mailing address of the legal entity. Required fields within the `legal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: Optional[List[str]] = None
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """

    administrative_area: Optional[str] = None
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""

    language_code: Optional[str] = None
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """

    locality: Optional[str] = None
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""

    organization: Optional[str] = None
    r"""Optional. The name of the organization at the address."""

    postal_code: Optional[str] = None
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""

    recipients: Optional[List[str]] = None
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""

    region_code: Optional[str] = None
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""

    revision: Optional[int] = None
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """

    sorting_code: Optional[str] = None
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""

    sublocality: Optional[str] = None
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyTaxIDType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The nature of the U.S. Tax ID indicated in the related tax_id field; Examples include ITIN, SSN, EIN."""

    TAX_ID_TYPE_UNSPECIFIED = "TAX_ID_TYPE_UNSPECIFIED"
    TAX_ID_TYPE_SSN = "TAX_ID_TYPE_SSN"
    TAX_ID_TYPE_ITIN = "TAX_ID_TYPE_ITIN"
    TAX_ID_TYPE_EIN = "TAX_ID_TYPE_EIN"


class PartyCNoticeDateTypedDict(TypedDict):
    r"""C Notice date."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyCNoticeDate(BaseModel):
    r"""C Notice date."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyFederalTaxClassification(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Federal tax classification."""

    FEDERAL_TAX_CLASSIFICATION_UNSPECIFIED = "FEDERAL_TAX_CLASSIFICATION_UNSPECIFIED"
    INDIV_SOLEPROP_OR_SINGLEMEMBERLLC = "INDIV_SOLEPROP_OR_SINGLEMEMBERLLC"
    PARTNERSHIP = "PARTNERSHIP"
    C_CORPORATION = "C_CORPORATION"
    S_CORPORATION = "S_CORPORATION"
    TRUST_ESTATE = "TRUST_ESTATE"
    LLC_TAXED_AS_C_CORP = "LLC_TAXED_AS_C_CORP"
    LLC_TAXED_AS_S_CORP = "LLC_TAXED_AS_S_CORP"
    LLC_TAXED_AS_PARTNERSHIP = "LLC_TAXED_AS_PARTNERSHIP"
    OTHER = "OTHER"


class PartyFirstBNoticeDateTypedDict(TypedDict):
    r"""Initial B Notice date."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyFirstBNoticeDate(BaseModel):
    r"""Initial B Notice date."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyIrsFormType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""IRS form type."""

    IRS_FORM_TYPE_UNSPECIFIED = "IRS_FORM_TYPE_UNSPECIFIED"
    W_9 = "W_9"


class PartyReportingEligibility(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Tax reporting eligibility."""

    TAX_REPORTING_ELIGIBILITY_UNSPECIFIED = "TAX_REPORTING_ELIGIBILITY_UNSPECIFIED"
    ELIGIBLE = "ELIGIBLE"
    INELIGIBLE = "INELIGIBLE"


class PartyTaxCertificationDateTypedDict(TypedDict):
    r"""Tax Certification date."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyTaxCertificationDate(BaseModel):
    r"""Tax Certification date."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyTaxpayerCertificationState(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Taxpayer certification status."""

    TAXPAYER_CERTIFICATION_STATE_UNSPECIFIED = (
        "TAXPAYER_CERTIFICATION_STATE_UNSPECIFIED"
    )
    CERTIFIED = "CERTIFIED"
    UNCERTIFIED = "UNCERTIFIED"


class PartyUsTinStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""United States Individual Taxpayer Identification Number (ITIN) status."""

    US_TIN_STATUS_UNSPECIFIED = "US_TIN_STATUS_UNSPECIFIED"
    PASSING = "PASSING"
    FAILING = "FAILING"


class PartyWithholdingState(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""B/C Notice status."""

    WITHHOLDING_STATE_UNSPECIFIED = "WITHHOLDING_STATE_UNSPECIFIED"
    FIRST_B_NOTICE_RECEIVED = "FIRST_B_NOTICE_RECEIVED"
    SECOND_B_NOTICE_RECEIVED = "SECOND_B_NOTICE_RECEIVED"
    C_NOTICE_RECEIVED = "C_NOTICE_RECEIVED"
    C_NOTICE_INDICATED_BY_CUSTOMER = "C_NOTICE_INDICATED_BY_CUSTOMER"


class PartyTaxProfileTypedDict(TypedDict):
    r"""The tax profile for the legal entity."""

    c_notice_date: NotRequired[Nullable[PartyCNoticeDateTypedDict]]
    r"""C Notice date."""
    federal_tax_classification: NotRequired[PartyFederalTaxClassification]
    r"""Federal tax classification."""
    first_b_notice_date: NotRequired[Nullable[PartyFirstBNoticeDateTypedDict]]
    r"""Initial B Notice date."""
    irs_form_type: NotRequired[PartyIrsFormType]
    r"""IRS form type."""
    legal_tax_region_code: NotRequired[str]
    r"""Legal tax region must be \"US\" if provided W-9, otherwise must be a non-US country."""
    reporting_eligibility: NotRequired[PartyReportingEligibility]
    r"""Tax reporting eligibility."""
    tax_certification_date: NotRequired[Nullable[PartyTaxCertificationDateTypedDict]]
    r"""Tax Certification date."""
    taxpayer_certification_state: NotRequired[PartyTaxpayerCertificationState]
    r"""Taxpayer certification status."""
    us_tin_status: NotRequired[PartyUsTinStatus]
    r"""United States Individual Taxpayer Identification Number (ITIN) status."""
    withholding_state: NotRequired[PartyWithholdingState]
    r"""B/C Notice status."""


class PartyTaxProfile(BaseModel):
    r"""The tax profile for the legal entity."""

    c_notice_date: OptionalNullable[PartyCNoticeDate] = UNSET
    r"""C Notice date."""

    federal_tax_classification: Annotated[
        Optional[PartyFederalTaxClassification],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Federal tax classification."""

    first_b_notice_date: OptionalNullable[PartyFirstBNoticeDate] = UNSET
    r"""Initial B Notice date."""

    irs_form_type: Annotated[
        Optional[PartyIrsFormType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""IRS form type."""

    legal_tax_region_code: Optional[str] = None
    r"""Legal tax region must be \"US\" if provided W-9, otherwise must be a non-US country."""

    reporting_eligibility: Annotated[
        Optional[PartyReportingEligibility], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Tax reporting eligibility."""

    tax_certification_date: OptionalNullable[PartyTaxCertificationDate] = UNSET
    r"""Tax Certification date."""

    taxpayer_certification_state: Annotated[
        Optional[PartyTaxpayerCertificationState],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Taxpayer certification status."""

    us_tin_status: Annotated[
        Optional[PartyUsTinStatus], PlainValidator(validate_open_enum(False))
    ] = None
    r"""United States Individual Taxpayer Identification Number (ITIN) status."""

    withholding_state: Annotated[
        Optional[PartyWithholdingState], PlainValidator(validate_open_enum(False))
    ] = None
    r"""B/C Notice status."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "c_notice_date",
            "federal_tax_classification",
            "first_b_notice_date",
            "irs_form_type",
            "legal_tax_region_code",
            "reporting_eligibility",
            "tax_certification_date",
            "taxpayer_certification_state",
            "us_tin_status",
            "withholding_state",
        ]
        nullable_fields = [
            "c_notice_date",
            "first_b_notice_date",
            "tax_certification_date",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyLegalEntityTypedDict(TypedDict):
    r"""Legal entity."""

    accredited_investor: NotRequired[bool]
    r"""Indicates whether the entity is an accredited investor. By default, this is set to `false`."""
    adviser: NotRequired[bool]
    r"""Indicates whether the entity is an adviser. By default, this is set to `false`."""
    broker_dealer: NotRequired[bool]
    r"""Indicates whether the entity is a broker dealer. By default, this is set to `false`."""
    business_industrial_classification: NotRequired[
        PartyBusinessIndustrialClassification
    ]
    corporate_structure: NotRequired[PartyCorporateStructure]
    r"""Corporate structure of the entity."""
    correspondent_id: NotRequired[str]
    r"""The correspondent id associated with the legal entity."""
    doing_business_as: NotRequired[List[str]]
    r"""DBA (Doing Business As) names. Can list up to 5 associated with the Legal Entity"""
    entity_due_diligence: NotRequired[Nullable[PartyEntityDueDiligenceTypedDict]]
    r"""Due Diligence for Legal Entities"""
    entity_name: NotRequired[str]
    r"""The legal entity name."""
    entity_type: NotRequired[PartyEntityType]
    r"""The entity type."""
    exempt_customer_reason: NotRequired[PartyExemptCustomerReason]
    r"""The reason the customer is exempt from verifying beneficial owners, if applicable."""
    exempt_verifying_beneficial_owners: NotRequired[bool]
    r"""Indicates whether the entity is exempt from verifying beneficial owners. By default, this is set to `false`."""
    for_the_benefit_of: NotRequired[str]
    r"""If the legal entity is a trust, they may set this field to convey ownership and value to a trustee."""
    foreign_entity: NotRequired[bool]
    r"""Indicates whether the entity is a foreign entity. By default, this is set to `false`."""
    foreign_financial_institution: NotRequired[bool]
    r"""Indicates whether the entity is a foreign financial institution. By default, this is set to `false`."""
    formation_date: NotRequired[Nullable[PartyFormationDateTypedDict]]
    r"""If the legal entity is a trust, the formation date is required."""
    global_person_id: NotRequired[str]
    r"""Globally Unique identifier for a legal natural person"""
    institutional_customer: NotRequired[bool]
    r"""Indicates whether the entity is an institutional customer"""
    investigation_id: NotRequired[str]
    r"""Investigation id relating to the Customer Identification Program (CIP) and Customer Due Diligence (CDD)."""
    large_trader: NotRequired[Nullable[PartyLargeTraderTypedDict]]
    r"""Large trader for the legal entity."""
    legal_address: NotRequired[Nullable[PartyLegalAddressTypedDict]]
    r"""The mailing address of the legal entity. Required fields within the `legal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """
    legal_entity_id: NotRequired[str]
    r"""A system-generated unique identifier referencing a single juridical (non-natural) person (e.g., a corporation); Used to access the record after creation"""
    lei_code: NotRequired[str]
    r"""The Legal Entity Identifier (LEI) is the financial industry term for a unique global identifier for legal entities participating in financial transactions"""
    name: NotRequired[str]
    r"""The name field Format: legalEntities/{legalEntity}"""
    operating_regions: NotRequired[List[str]]
    r"""The operational footprint of an entity. Operating regions encompass all countries and regions where a company has a significant business presence This includes locations with physical offices, manufacturing plants, service centers, and sales and marketing activities Regions must be provided as two-character CLDR country codes"""
    registration_region: NotRequired[str]
    r"""The legal home of an entity. A region of registration, in the context of a corporation, refers to the specific geographic area where the corporation is legally registered and incorporated Defines the legal jurisdiction and framework under which the corporation operates, including legal regulations, tax obligations, and compliance requirements Region must be provided as a two-character CLDR country code"""
    regulated_investment_company: NotRequired[bool]
    r"""Indicates whether the entity is a regulated investment company. By default, this is set to `false`."""
    related_document_ids: NotRequired[List[str]]
    r"""Document ids related to the legal entity. At least one is required for RIA correspondents when creating Estate or Trust accounts."""
    revocable_trust: NotRequired[bool]
    r"""Indicates whether the trust is a revocable trust. By default, this is set to `false`."""
    tax_id: NotRequired[str]
    r"""The full U.S. tax ID for a related entity; Must be provided with `EIN` tax ID type"""
    tax_id_last_four: NotRequired[str]
    r"""The last four characters of the related person's tax identifier; Masked/truncated to \"last four\" in most usage contexts to preserve data privacy."""
    tax_id_type: NotRequired[PartyTaxIDType]
    r"""The nature of the U.S. Tax ID indicated in the related tax_id field; Examples include ITIN, SSN, EIN."""
    tax_profile: NotRequired[Nullable[PartyTaxProfileTypedDict]]
    r"""The tax profile for the legal entity."""


class PartyLegalEntity(BaseModel):
    r"""Legal entity."""

    accredited_investor: Optional[bool] = None
    r"""Indicates whether the entity is an accredited investor. By default, this is set to `false`."""

    adviser: Optional[bool] = None
    r"""Indicates whether the entity is an adviser. By default, this is set to `false`."""

    broker_dealer: Optional[bool] = None
    r"""Indicates whether the entity is a broker dealer. By default, this is set to `false`."""

    business_industrial_classification: Annotated[
        Optional[PartyBusinessIndustrialClassification],
        PlainValidator(validate_open_enum(False)),
    ] = None

    corporate_structure: Annotated[
        Optional[PartyCorporateStructure], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Corporate structure of the entity."""

    correspondent_id: Optional[str] = None
    r"""The correspondent id associated with the legal entity."""

    doing_business_as: Optional[List[str]] = None
    r"""DBA (Doing Business As) names. Can list up to 5 associated with the Legal Entity"""

    entity_due_diligence: OptionalNullable[PartyEntityDueDiligence] = UNSET
    r"""Due Diligence for Legal Entities"""

    entity_name: Optional[str] = None
    r"""The legal entity name."""

    entity_type: Annotated[
        Optional[PartyEntityType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The entity type."""

    exempt_customer_reason: Annotated[
        Optional[PartyExemptCustomerReason], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The reason the customer is exempt from verifying beneficial owners, if applicable."""

    exempt_verifying_beneficial_owners: Optional[bool] = None
    r"""Indicates whether the entity is exempt from verifying beneficial owners. By default, this is set to `false`."""

    for_the_benefit_of: Optional[str] = None
    r"""If the legal entity is a trust, they may set this field to convey ownership and value to a trustee."""

    foreign_entity: Optional[bool] = None
    r"""Indicates whether the entity is a foreign entity. By default, this is set to `false`."""

    foreign_financial_institution: Optional[bool] = None
    r"""Indicates whether the entity is a foreign financial institution. By default, this is set to `false`."""

    formation_date: OptionalNullable[PartyFormationDate] = UNSET
    r"""If the legal entity is a trust, the formation date is required."""

    global_person_id: Optional[str] = None
    r"""Globally Unique identifier for a legal natural person"""

    institutional_customer: Optional[bool] = None
    r"""Indicates whether the entity is an institutional customer"""

    investigation_id: Optional[str] = None
    r"""Investigation id relating to the Customer Identification Program (CIP) and Customer Due Diligence (CDD)."""

    large_trader: OptionalNullable[PartyLargeTrader] = UNSET
    r"""Large trader for the legal entity."""

    legal_address: OptionalNullable[PartyLegalAddress] = UNSET
    r"""The mailing address of the legal entity. Required fields within the `legal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    legal_entity_id: Optional[str] = None
    r"""A system-generated unique identifier referencing a single juridical (non-natural) person (e.g., a corporation); Used to access the record after creation"""

    lei_code: Optional[str] = None
    r"""The Legal Entity Identifier (LEI) is the financial industry term for a unique global identifier for legal entities participating in financial transactions"""

    name: Optional[str] = None
    r"""The name field Format: legalEntities/{legalEntity}"""

    operating_regions: Optional[List[str]] = None
    r"""The operational footprint of an entity. Operating regions encompass all countries and regions where a company has a significant business presence This includes locations with physical offices, manufacturing plants, service centers, and sales and marketing activities Regions must be provided as two-character CLDR country codes"""

    registration_region: Optional[str] = None
    r"""The legal home of an entity. A region of registration, in the context of a corporation, refers to the specific geographic area where the corporation is legally registered and incorporated Defines the legal jurisdiction and framework under which the corporation operates, including legal regulations, tax obligations, and compliance requirements Region must be provided as a two-character CLDR country code"""

    regulated_investment_company: Optional[bool] = None
    r"""Indicates whether the entity is a regulated investment company. By default, this is set to `false`."""

    related_document_ids: Optional[List[str]] = None
    r"""Document ids related to the legal entity. At least one is required for RIA correspondents when creating Estate or Trust accounts."""

    revocable_trust: Optional[bool] = None
    r"""Indicates whether the trust is a revocable trust. By default, this is set to `false`."""

    tax_id: Optional[str] = None
    r"""The full U.S. tax ID for a related entity; Must be provided with `EIN` tax ID type"""

    tax_id_last_four: Optional[str] = None
    r"""The last four characters of the related person's tax identifier; Masked/truncated to \"last four\" in most usage contexts to preserve data privacy."""

    tax_id_type: Annotated[
        Optional[PartyTaxIDType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The nature of the U.S. Tax ID indicated in the related tax_id field; Examples include ITIN, SSN, EIN."""

    tax_profile: OptionalNullable[PartyTaxProfile] = UNSET
    r"""The tax profile for the legal entity."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "accredited_investor",
            "adviser",
            "broker_dealer",
            "business_industrial_classification",
            "corporate_structure",
            "correspondent_id",
            "doing_business_as",
            "entity_due_diligence",
            "entity_name",
            "entity_type",
            "exempt_customer_reason",
            "exempt_verifying_beneficial_owners",
            "for_the_benefit_of",
            "foreign_entity",
            "foreign_financial_institution",
            "formation_date",
            "global_person_id",
            "institutional_customer",
            "investigation_id",
            "large_trader",
            "legal_address",
            "legal_entity_id",
            "lei_code",
            "name",
            "operating_regions",
            "registration_region",
            "regulated_investment_company",
            "related_document_ids",
            "revocable_trust",
            "tax_id",
            "tax_id_last_four",
            "tax_id_type",
            "tax_profile",
        ]
        nullable_fields = [
            "entity_due_diligence",
            "formation_date",
            "large_trader",
            "legal_address",
            "tax_profile",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyBirthDateTypedDict(TypedDict):
    r"""The legal day, month, and year of birth for a natural person."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyBirthDate(BaseModel):
    r"""The legal day, month, and year of birth for a natural person."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyDeathDateTypedDict(TypedDict):
    r"""The day, month, and year of death of a legal natural person"""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyDeathDate(BaseModel):
    r"""The day, month, and year of death of a legal natural person"""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyEmployerAddressTypedDict(TypedDict):
    r"""The data structure containing attributes describing the location of an investor's employer. If input, the required fields within the `employer_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: NotRequired[List[str]]
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """
    administrative_area: NotRequired[str]
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""
    language_code: NotRequired[str]
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """
    locality: NotRequired[str]
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""
    organization: NotRequired[str]
    r"""Optional. The name of the organization at the address."""
    postal_code: NotRequired[str]
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""
    recipients: NotRequired[List[str]]
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""
    region_code: NotRequired[str]
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""
    revision: NotRequired[int]
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """
    sorting_code: NotRequired[str]
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""
    sublocality: NotRequired[str]
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyEmployerAddress(BaseModel):
    r"""The data structure containing attributes describing the location of an investor's employer. If input, the required fields within the `employer_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: Optional[List[str]] = None
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """

    administrative_area: Optional[str] = None
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""

    language_code: Optional[str] = None
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """

    locality: Optional[str] = None
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""

    organization: Optional[str] = None
    r"""Optional. The name of the organization at the address."""

    postal_code: Optional[str] = None
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""

    recipients: Optional[List[str]] = None
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""

    region_code: Optional[str] = None
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""

    revision: Optional[int] = None
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """

    sorting_code: Optional[str] = None
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""

    sublocality: Optional[str] = None
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyEmploymentStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Classifies in what capacity (or if) the underlying natural person holds a job"""

    STATUS_UNSPECIFIED = "STATUS_UNSPECIFIED"
    EMPLOYED = "EMPLOYED"
    SELF_EMPLOYED = "SELF_EMPLOYED"
    UNEMPLOYED = "UNEMPLOYED"
    RETIRED = "RETIRED"
    STUDENT = "STUDENT"


class PartyEmploymentTypedDict(TypedDict):
    r"""Object containing information pertaining to a investor's current employer including the name, address, and duration of employment."""

    employer: NotRequired[str]
    r"""The business name of an investor's employer."""
    employer_address: NotRequired[Nullable[PartyEmployerAddressTypedDict]]
    r"""The data structure containing attributes describing the location of an investor's employer. If input, the required fields within the `employer_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """
    employment_id: NotRequired[str]
    r"""System-generated GUID representing the employment record of a natural person"""
    employment_status: NotRequired[PartyEmploymentStatus]
    r"""Classifies in what capacity (or if) the underlying natural person holds a job"""
    occupation: NotRequired[str]
    r"""The nature of work performed at an investor's place of employment."""
    start_year: NotRequired[int]
    r"""The start year of employment related to a person's stated employer Must be from birth year to current year, or 0 to clear start year value"""


class PartyEmployment(BaseModel):
    r"""Object containing information pertaining to a investor's current employer including the name, address, and duration of employment."""

    employer: Optional[str] = None
    r"""The business name of an investor's employer."""

    employer_address: OptionalNullable[PartyEmployerAddress] = UNSET
    r"""The data structure containing attributes describing the location of an investor's employer. If input, the required fields within the `employer_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    employment_id: Optional[str] = None
    r"""System-generated GUID representing the employment record of a natural person"""

    employment_status: Annotated[
        Optional[PartyEmploymentStatus], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Classifies in what capacity (or if) the underlying natural person holds a job"""

    occupation: Optional[str] = None
    r"""The nature of work performed at an investor's place of employment."""

    start_year: Optional[int] = None
    r"""The start year of employment related to a person's stated employer Must be from birth year to current year, or 0 to clear start year value"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "employer",
            "employer_address",
            "employment_id",
            "employment_status",
            "occupation",
            "start_year",
        ]
        nullable_fields = ["employer_address"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyExpirationDateTypedDict(TypedDict):
    r"""Identification expiration date"""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyExpirationDate(BaseModel):
    r"""Identification expiration date"""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyIssueDateTypedDict(TypedDict):
    r"""Identification issue date"""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyIssueDate(BaseModel):
    r"""Identification issue date"""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Identification type"""

    IDENTIFICATION_TYPE_UNSPECIFIED = "IDENTIFICATION_TYPE_UNSPECIFIED"
    PASSPORT = "PASSPORT"
    NATIONAL_ID = "NATIONAL_ID"
    DRIVERS_LICENSE = "DRIVERS_LICENSE"


class PartyForeignIdentificationTypedDict(TypedDict):
    r"""Foreign identification. Must be provided if the person does not have a U.S. tax ID"""

    expiration_date: NotRequired[Nullable[PartyExpirationDateTypedDict]]
    r"""Identification expiration date"""
    ftin: NotRequired[bool]
    r"""Denotes if the identification is a tax id or other"""
    identification_number: NotRequired[str]
    r"""Identification number"""
    issue_date: NotRequired[Nullable[PartyIssueDateTypedDict]]
    r"""Identification issue date"""
    issuing_region_code: NotRequired[str]
    r"""Region of issuance must be provided as a two-character CLDR country code"""
    type: NotRequired[PartyLegalNaturalPersonType]
    r"""Identification type"""


class PartyForeignIdentification(BaseModel):
    r"""Foreign identification. Must be provided if the person does not have a U.S. tax ID"""

    expiration_date: OptionalNullable[PartyExpirationDate] = UNSET
    r"""Identification expiration date"""

    ftin: Optional[bool] = None
    r"""Denotes if the identification is a tax id or other"""

    identification_number: Optional[str] = None
    r"""Identification number"""

    issue_date: OptionalNullable[PartyIssueDate] = UNSET
    r"""Identification issue date"""

    issuing_region_code: Optional[str] = None
    r"""Region of issuance must be provided as a two-character CLDR country code"""

    type: Annotated[
        Optional[PartyLegalNaturalPersonType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Identification type"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "expiration_date",
            "ftin",
            "identification_number",
            "issue_date",
            "issuing_region_code",
            "type",
        ]
        nullable_fields = ["expiration_date", "issue_date"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyExecutionDateTypedDict(TypedDict):
    r"""The datetime external identity verification results were run on a natural person"""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyExecutionDate(BaseModel):
    r"""The datetime external identity verification results were run on a natural person"""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyIdentityVerificationResultTypedDict(TypedDict):
    r"""Third-party data result used to verify the identity of an introduced investor. If the client identity_verification_model is PROVIDED_BY_CLIENT, this field is required"""

    address_verified: NotRequired[bool]
    r"""Attestation that external result and review have verified the supplied investor's address has been verified in conjunction with other PII"""
    birth_date_verified: NotRequired[bool]
    r"""Attestation that external result and review have verified the supplied investor's date of birth has been verified in conjunction with other PII"""
    execution_date: NotRequired[Nullable[PartyExecutionDateTypedDict]]
    r"""The datetime external identity verification results were run on a natural person"""
    external_case_id: NotRequired[str]
    r"""Client-generated identifier associated with the KYC results for the appropriate case"""
    identity_verification_document_ids: NotRequired[List[str]]
    r"""System generated document IDs returned after uploading identity documents to the Documents API"""
    identity_verification_result_id: NotRequired[str]
    r"""System-generated GUID used to uniquely identify the verification_result"""
    name_verified: NotRequired[bool]
    r"""Attestation that external result and review have verified the supplied investor's name has been verified in conjunction with other PII"""
    raw_vendor_data_document_id: NotRequired[str]
    r"""A system-generated document ID assigned when raw vendor results are uploaded to the Documents API; This field is optional for person record creation, but required for account creation if the Correspondent provides IDV results"""
    tax_id_verified: NotRequired[bool]
    r"""Attestation that external result and review have verified the supplied investor's Tax ID has been verified in conjunction with other PII"""
    vendor: NotRequired[str]
    r"""The name(s) of the vendor(s) used to externally verify and screen a natural person; relates to the identity_verification_result"""


class PartyIdentityVerificationResult(BaseModel):
    r"""Third-party data result used to verify the identity of an introduced investor. If the client identity_verification_model is PROVIDED_BY_CLIENT, this field is required"""

    address_verified: Optional[bool] = None
    r"""Attestation that external result and review have verified the supplied investor's address has been verified in conjunction with other PII"""

    birth_date_verified: Optional[bool] = None
    r"""Attestation that external result and review have verified the supplied investor's date of birth has been verified in conjunction with other PII"""

    execution_date: OptionalNullable[PartyExecutionDate] = UNSET
    r"""The datetime external identity verification results were run on a natural person"""

    external_case_id: Optional[str] = None
    r"""Client-generated identifier associated with the KYC results for the appropriate case"""

    identity_verification_document_ids: Optional[List[str]] = None
    r"""System generated document IDs returned after uploading identity documents to the Documents API"""

    identity_verification_result_id: Optional[str] = None
    r"""System-generated GUID used to uniquely identify the verification_result"""

    name_verified: Optional[bool] = None
    r"""Attestation that external result and review have verified the supplied investor's name has been verified in conjunction with other PII"""

    raw_vendor_data_document_id: Optional[str] = None
    r"""A system-generated document ID assigned when raw vendor results are uploaded to the Documents API; This field is optional for person record creation, but required for account creation if the Correspondent provides IDV results"""

    tax_id_verified: Optional[bool] = None
    r"""Attestation that external result and review have verified the supplied investor's Tax ID has been verified in conjunction with other PII"""

    vendor: Optional[str] = None
    r"""The name(s) of the vendor(s) used to externally verify and screen a natural person; relates to the identity_verification_result"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "address_verified",
            "birth_date_verified",
            "execution_date",
            "external_case_id",
            "identity_verification_document_ids",
            "identity_verification_result_id",
            "name_verified",
            "raw_vendor_data_document_id",
            "tax_id_verified",
            "vendor",
        ]
        nullable_fields = ["execution_date"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyLegalNaturalPersonEffectiveDateTypedDict(TypedDict):
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonEffectiveDate(BaseModel):
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonLargeTraderTypedDict(TypedDict):
    r"""Indicates if the person is recognized as a \"Large Trader\" by the SEC."""

    effective_date: NotRequired[Nullable[PartyLegalNaturalPersonEffectiveDateTypedDict]]
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""
    large_trader_id: NotRequired[str]
    r"""SEC-issued ID signifying the person/entity as a large trader; Required for CAIS regulatory reporting."""


class PartyLegalNaturalPersonLargeTrader(BaseModel):
    r"""Indicates if the person is recognized as a \"Large Trader\" by the SEC."""

    effective_date: OptionalNullable[PartyLegalNaturalPersonEffectiveDate] = UNSET
    r"""The date on which the trader meets or exceeds the large trader reporting threshold, which is defined by the U.S. Securities and Exchange Commission (SEC) as trades of 2 million shares or $20 million in a single day or 20 million shares or $200 million during a calendar month"""

    large_trader_id: Optional[str] = None
    r"""SEC-issued ID signifying the person/entity as a large trader; Required for CAIS regulatory reporting."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["effective_date", "large_trader_id"]
        nullable_fields = ["effective_date"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyMaritalStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The legal marital status of an account-holder; Used in combination with state of domicile to determine qualification for account types and beneficiary exclusion rules."""

    MARITAL_STATUS_UNSPECIFIED = "MARITAL_STATUS_UNSPECIFIED"
    SINGLE = "SINGLE"
    MARRIED = "MARRIED"
    DIVORCED = "DIVORCED"
    WIDOWED = "WIDOWED"


class PartyNameSuffix(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The suffix of a natural person; A suffix in a name is any part of the name that comes after the last name"""

    NAME_SUFFIX_UNSPECIFIED = "NAME_SUFFIX_UNSPECIFIED"
    SR = "SR"
    JR = "JR"
    III = "III"
    IV = "IV"
    V = "V"


class PartyCustomerReferralSourceTypedDict(TypedDict):
    r"""Customer Referral Source"""

    name: NotRequired[str]
    r"""The name of the referrer"""
    relationship_to_applicant: NotRequired[str]
    r"""The relationship of the referrer to the applicant"""
    relationship_years_with_applicant: NotRequired[int]
    r"""The years the referrer has known the applicant If the referrer has known the applicant for less than a year, they must specify 1"""
    relationship_years_with_broker: NotRequired[int]
    r"""The years the referrer has known the broker If the referrer has known the broker for less than a year, they must specify 1"""


class PartyCustomerReferralSource(BaseModel):
    r"""Customer Referral Source"""

    name: Optional[str] = None
    r"""The name of the referrer"""

    relationship_to_applicant: Optional[str] = None
    r"""The relationship of the referrer to the applicant"""

    relationship_years_with_applicant: Optional[int] = None
    r"""The years the referrer has known the applicant If the referrer has known the applicant for less than a year, they must specify 1"""

    relationship_years_with_broker: Optional[int] = None
    r"""The years the referrer has known the broker If the referrer has known the broker for less than a year, they must specify 1"""


class PartyLegalNaturalPersonNegativeNewsTypedDict(TypedDict):
    r"""Information about any negative news against the client, or any immediate family members, close associates, or related entities"""

    negative_news_against_related_parties: NotRequired[bool]
    r"""Indicates whether there is negative news against related parties"""
    negative_news_against_related_parties_description: NotRequired[str]
    r"""Description of the negative news against related parties"""


class PartyLegalNaturalPersonNegativeNews(BaseModel):
    r"""Information about any negative news against the client, or any immediate family members, close associates, or related entities"""

    negative_news_against_related_parties: Optional[bool] = None
    r"""Indicates whether there is negative news against related parties"""

    negative_news_against_related_parties_description: Optional[str] = None
    r"""Description of the negative news against related parties"""


class PartyOtherSourcesOfWealthTypedDict(TypedDict):
    r"""The applicant's other source of wealth"""

    applicant_has_other_sources_of_wealth: NotRequired[bool]
    r"""Indicates whether the applicant has other sources of wealth."""
    other_sources_of_wealth: NotRequired[str]
    r"""The applicant's other source of wealth description. If the applicant has no other sources of wealth, they must specify \"N/A.\" """
    other_sources_of_wealth_verification: NotRequired[str]
    r"""The applicant's other source of wealth verification. If the applicant has no other sources of wealth, they must specify \"N/A.\" """


class PartyOtherSourcesOfWealth(BaseModel):
    r"""The applicant's other source of wealth"""

    applicant_has_other_sources_of_wealth: Optional[bool] = None
    r"""Indicates whether the applicant has other sources of wealth."""

    other_sources_of_wealth: Optional[str] = None
    r"""The applicant's other source of wealth description. If the applicant has no other sources of wealth, they must specify \"N/A.\" """

    other_sources_of_wealth_verification: Optional[str] = None
    r"""The applicant's other source of wealth verification. If the applicant has no other sources of wealth, they must specify \"N/A.\" """


class PartyNaturalPersonFddTypedDict(TypedDict):
    r"""Foreign Due Diligence (FDD) information for Legal Natural Person"""

    customer_non_referral_source: NotRequired[str]
    r"""Customer Non-referral Source"""
    customer_referral_source: NotRequired[
        Nullable[PartyCustomerReferralSourceTypedDict]
    ]
    r"""Customer Referral Source"""
    employment_and_employer_description: NotRequired[str]
    r"""The description of the applicant's source of wealth"""
    negative_news: NotRequired[Nullable[PartyLegalNaturalPersonNegativeNewsTypedDict]]
    r"""Information about any negative news against the client, or any immediate family members, close associates, or related entities"""
    other_sources_of_wealth: NotRequired[Nullable[PartyOtherSourcesOfWealthTypedDict]]
    r"""The applicant's other source of wealth"""


class PartyNaturalPersonFdd(BaseModel):
    r"""Foreign Due Diligence (FDD) information for Legal Natural Person"""

    customer_non_referral_source: Optional[str] = None
    r"""Customer Non-referral Source"""

    customer_referral_source: OptionalNullable[PartyCustomerReferralSource] = UNSET
    r"""Customer Referral Source"""

    employment_and_employer_description: Optional[str] = None
    r"""The description of the applicant's source of wealth"""

    negative_news: OptionalNullable[PartyLegalNaturalPersonNegativeNews] = UNSET
    r"""Information about any negative news against the client, or any immediate family members, close associates, or related entities"""

    other_sources_of_wealth: OptionalNullable[PartyOtherSourcesOfWealth] = UNSET
    r"""The applicant's other source of wealth"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "customer_non_referral_source",
            "customer_referral_source",
            "employment_and_employer_description",
            "negative_news",
            "other_sources_of_wealth",
        ]
        nullable_fields = [
            "customer_referral_source",
            "negative_news",
            "other_sources_of_wealth",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyResidencyStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    RESIDENCY_STATUS_UNSPECIFIED = "RESIDENCY_STATUS_UNSPECIFIED"
    US_PERMANENT_RESIDENT = "US_PERMANENT_RESIDENT"
    US_TEMPORARY_RESIDENT = "US_TEMPORARY_RESIDENT"
    US_NON_RESIDENT = "US_NON_RESIDENT"


class PartyNonCitizenResidencyTypedDict(TypedDict):
    r"""Facilitates non-citizen lawful US residents to open domestic accounts"""

    residency_status: NotRequired[PartyResidencyStatus]


class PartyNonCitizenResidency(BaseModel):
    r"""Facilitates non-citizen lawful US residents to open domestic accounts"""

    residency_status: Annotated[
        Optional[PartyResidencyStatus], PlainValidator(validate_open_enum(False))
    ] = None


class PartyPersonalAddressTypedDict(TypedDict):
    r"""The legal street number and street name for an account Party. Required fields within the `personal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: NotRequired[List[str]]
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """
    administrative_area: NotRequired[str]
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""
    language_code: NotRequired[str]
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """
    locality: NotRequired[str]
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""
    organization: NotRequired[str]
    r"""Optional. The name of the organization at the address."""
    postal_code: NotRequired[str]
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""
    recipients: NotRequired[List[str]]
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""
    region_code: NotRequired[str]
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""
    revision: NotRequired[int]
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """
    sorting_code: NotRequired[str]
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""
    sublocality: NotRequired[str]
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyPersonalAddress(BaseModel):
    r"""The legal street number and street name for an account Party. Required fields within the `personal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: Optional[List[str]] = None
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """

    administrative_area: Optional[str] = None
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""

    language_code: Optional[str] = None
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """

    locality: Optional[str] = None
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""

    organization: Optional[str] = None
    r"""Optional. The name of the organization at the address."""

    postal_code: Optional[str] = None
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""

    recipients: Optional[List[str]] = None
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""

    region_code: Optional[str] = None
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""

    revision: Optional[int] = None
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """

    sorting_code: Optional[str] = None
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""

    sublocality: Optional[str] = None
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyLegalNaturalPersonTaxIDType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The nature of the U.S. Tax ID indicated in the related tax_id field; Examples include ITIN, SSN, EIN."""

    TAX_ID_TYPE_UNSPECIFIED = "TAX_ID_TYPE_UNSPECIFIED"
    TAX_ID_TYPE_SSN = "TAX_ID_TYPE_SSN"
    TAX_ID_TYPE_ITIN = "TAX_ID_TYPE_ITIN"
    TAX_ID_TYPE_EIN = "TAX_ID_TYPE_EIN"


class PartyLegalNaturalPersonCNoticeDateTypedDict(TypedDict):
    r"""C Notice date."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonCNoticeDate(BaseModel):
    r"""C Notice date."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonFederalTaxClassification(
    str, Enum, metaclass=utils.OpenEnumMeta
):
    r"""Federal tax classification."""

    FEDERAL_TAX_CLASSIFICATION_UNSPECIFIED = "FEDERAL_TAX_CLASSIFICATION_UNSPECIFIED"
    INDIV_SOLEPROP_OR_SINGLEMEMBERLLC = "INDIV_SOLEPROP_OR_SINGLEMEMBERLLC"
    PARTNERSHIP = "PARTNERSHIP"
    C_CORPORATION = "C_CORPORATION"
    S_CORPORATION = "S_CORPORATION"
    TRUST_ESTATE = "TRUST_ESTATE"
    LLC_TAXED_AS_C_CORP = "LLC_TAXED_AS_C_CORP"
    LLC_TAXED_AS_S_CORP = "LLC_TAXED_AS_S_CORP"
    LLC_TAXED_AS_PARTNERSHIP = "LLC_TAXED_AS_PARTNERSHIP"
    OTHER = "OTHER"


class PartyLegalNaturalPersonFirstBNoticeDateTypedDict(TypedDict):
    r"""Initial B Notice date."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonFirstBNoticeDate(BaseModel):
    r"""Initial B Notice date."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonIrsFormType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""IRS form type."""

    IRS_FORM_TYPE_UNSPECIFIED = "IRS_FORM_TYPE_UNSPECIFIED"
    W_9 = "W_9"


class PartyLegalNaturalPersonReportingEligibility(
    str, Enum, metaclass=utils.OpenEnumMeta
):
    r"""Tax reporting eligibility."""

    TAX_REPORTING_ELIGIBILITY_UNSPECIFIED = "TAX_REPORTING_ELIGIBILITY_UNSPECIFIED"
    ELIGIBLE = "ELIGIBLE"
    INELIGIBLE = "INELIGIBLE"


class PartyLegalNaturalPersonTaxCertificationDateTypedDict(TypedDict):
    r"""Tax Certification date."""

    day: NotRequired[int]
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""
    month: NotRequired[int]
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""
    year: NotRequired[int]
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonTaxCertificationDate(BaseModel):
    r"""Tax Certification date."""

    day: Optional[int] = None
    r"""Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant."""

    month: Optional[int] = None
    r"""Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day."""

    year: Optional[int] = None
    r"""Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year."""


class PartyLegalNaturalPersonTaxpayerCertificationState(
    str, Enum, metaclass=utils.OpenEnumMeta
):
    r"""Taxpayer certification status."""

    TAXPAYER_CERTIFICATION_STATE_UNSPECIFIED = (
        "TAXPAYER_CERTIFICATION_STATE_UNSPECIFIED"
    )
    CERTIFIED = "CERTIFIED"
    UNCERTIFIED = "UNCERTIFIED"


class PartyLegalNaturalPersonUsTinStatus(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""United States Individual Taxpayer Identification Number (ITIN) status."""

    US_TIN_STATUS_UNSPECIFIED = "US_TIN_STATUS_UNSPECIFIED"
    PASSING = "PASSING"
    FAILING = "FAILING"


class PartyLegalNaturalPersonWithholdingState(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""B/C Notice status."""

    WITHHOLDING_STATE_UNSPECIFIED = "WITHHOLDING_STATE_UNSPECIFIED"
    FIRST_B_NOTICE_RECEIVED = "FIRST_B_NOTICE_RECEIVED"
    SECOND_B_NOTICE_RECEIVED = "SECOND_B_NOTICE_RECEIVED"
    C_NOTICE_RECEIVED = "C_NOTICE_RECEIVED"
    C_NOTICE_INDICATED_BY_CUSTOMER = "C_NOTICE_INDICATED_BY_CUSTOMER"


class PartyLegalNaturalPersonTaxProfileTypedDict(TypedDict):
    r"""Tax-related attributes at the for the account; A tax profile with taxpayer attributes is located on the legal_natural_person or legal_entity objects elsewhere on the account record."""

    c_notice_date: NotRequired[Nullable[PartyLegalNaturalPersonCNoticeDateTypedDict]]
    r"""C Notice date."""
    federal_tax_classification: NotRequired[
        PartyLegalNaturalPersonFederalTaxClassification
    ]
    r"""Federal tax classification."""
    first_b_notice_date: NotRequired[
        Nullable[PartyLegalNaturalPersonFirstBNoticeDateTypedDict]
    ]
    r"""Initial B Notice date."""
    irs_form_type: NotRequired[PartyLegalNaturalPersonIrsFormType]
    r"""IRS form type."""
    legal_tax_region_code: NotRequired[str]
    r"""Legal tax region must be \"US\" if provided W-9, otherwise must be a non-US country."""
    reporting_eligibility: NotRequired[PartyLegalNaturalPersonReportingEligibility]
    r"""Tax reporting eligibility."""
    tax_certification_date: NotRequired[
        Nullable[PartyLegalNaturalPersonTaxCertificationDateTypedDict]
    ]
    r"""Tax Certification date."""
    taxpayer_certification_state: NotRequired[
        PartyLegalNaturalPersonTaxpayerCertificationState
    ]
    r"""Taxpayer certification status."""
    us_tin_status: NotRequired[PartyLegalNaturalPersonUsTinStatus]
    r"""United States Individual Taxpayer Identification Number (ITIN) status."""
    withholding_state: NotRequired[PartyLegalNaturalPersonWithholdingState]
    r"""B/C Notice status."""


class PartyLegalNaturalPersonTaxProfile(BaseModel):
    r"""Tax-related attributes at the for the account; A tax profile with taxpayer attributes is located on the legal_natural_person or legal_entity objects elsewhere on the account record."""

    c_notice_date: OptionalNullable[PartyLegalNaturalPersonCNoticeDate] = UNSET
    r"""C Notice date."""

    federal_tax_classification: Annotated[
        Optional[PartyLegalNaturalPersonFederalTaxClassification],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Federal tax classification."""

    first_b_notice_date: OptionalNullable[
        PartyLegalNaturalPersonFirstBNoticeDate
    ] = UNSET
    r"""Initial B Notice date."""

    irs_form_type: Annotated[
        Optional[PartyLegalNaturalPersonIrsFormType],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""IRS form type."""

    legal_tax_region_code: Optional[str] = None
    r"""Legal tax region must be \"US\" if provided W-9, otherwise must be a non-US country."""

    reporting_eligibility: Annotated[
        Optional[PartyLegalNaturalPersonReportingEligibility],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Tax reporting eligibility."""

    tax_certification_date: OptionalNullable[
        PartyLegalNaturalPersonTaxCertificationDate
    ] = UNSET
    r"""Tax Certification date."""

    taxpayer_certification_state: Annotated[
        Optional[PartyLegalNaturalPersonTaxpayerCertificationState],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Taxpayer certification status."""

    us_tin_status: Annotated[
        Optional[PartyLegalNaturalPersonUsTinStatus],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""United States Individual Taxpayer Identification Number (ITIN) status."""

    withholding_state: Annotated[
        Optional[PartyLegalNaturalPersonWithholdingState],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""B/C Notice status."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "c_notice_date",
            "federal_tax_classification",
            "first_b_notice_date",
            "irs_form_type",
            "legal_tax_region_code",
            "reporting_eligibility",
            "tax_certification_date",
            "taxpayer_certification_state",
            "us_tin_status",
            "withholding_state",
        ]
        nullable_fields = [
            "c_notice_date",
            "first_b_notice_date",
            "tax_certification_date",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyLegalNaturalPersonTypedDict(TypedDict):
    r"""Legal natural person."""

    accredited_investor: NotRequired[bool]
    r"""Indicates whether the person is an accredited investor"""
    adviser: NotRequired[bool]
    r"""Indicates whether the person is an adviser"""
    birth_date: NotRequired[Nullable[PartyBirthDateTypedDict]]
    r"""The legal day, month, and year of birth for a natural person."""
    citizenship_countries: NotRequired[List[str]]
    r"""This is used for tax (treaty) and country block list considerations Maximum list of two 2-char CLDR Code citizenship countries, e.g. US, CA"""
    control_person_company_symbols: NotRequired[str]
    r"""A list of ticker symbols in which the underlying person is a control person; control persons are defined as having significant influence over a company’s management and operations, typically through ownership of a large percentage of the company’s voting stock or through positions on the company’s board of directors or executive team"""
    correspondent_employee: NotRequired[bool]
    r"""Indicates the related owner record is an employee of the clearing broker's correspondent customer."""
    correspondent_id: NotRequired[str]
    r"""A unique identifier referencing a Correspondent; A Client may have several operating Correspondents within its purview."""
    custodian_employee: NotRequired[bool]
    r"""A flag to indicate whether this person is an employee of the correspondent."""
    death_date: NotRequired[Nullable[PartyDeathDateTypedDict]]
    r"""The day, month, and year of death of a legal natural person"""
    doing_business_as: NotRequired[List[str]]
    r"""DBA (Doing Business As) names. Can list up to 5 associated with the Legal Natural Person"""
    employment: NotRequired[Nullable[PartyEmploymentTypedDict]]
    r"""Object containing information pertaining to a investor's current employer including the name, address, and duration of employment."""
    family_name: NotRequired[str]
    r"""Family name of a natural person."""
    finra_associated_entity: NotRequired[str]
    r"""The name of the FINRA-associated entity the underlying natural person is affiliated with."""
    foreign_identification: NotRequired[Nullable[PartyForeignIdentificationTypedDict]]
    r"""Foreign identification. Must be provided if the person does not have a U.S. tax ID"""
    given_name: NotRequired[str]
    r"""The given name of a natural person; Conventionally known as 'first name' in most English-speaking countries."""
    global_person_id: NotRequired[str]
    r"""Globally Unique identifier for a legal natural person"""
    identity_verification_result: NotRequired[
        Nullable[PartyIdentityVerificationResultTypedDict]
    ]
    r"""Third-party data result used to verify the identity of an introduced investor. If the client identity_verification_model is PROVIDED_BY_CLIENT, this field is required"""
    institutional_customer: NotRequired[bool]
    r"""Indicates whether the person is an institutional customer"""
    investigation_id: NotRequired[str]
    r"""Investigation id relating to the Customer Identification Program (CIP) and Customer Due Diligence (CDD)."""
    large_trader: NotRequired[Nullable[PartyLegalNaturalPersonLargeTraderTypedDict]]
    r"""Indicates if the person is recognized as a \"Large Trader\" by the SEC."""
    legal_natural_person_id: NotRequired[str]
    r"""A system-generated unique identifier referencing a single natural person; Used to access the record after creation."""
    marital_status: NotRequired[PartyMaritalStatus]
    r"""The legal marital status of an account-holder; Used in combination with state of domicile to determine qualification for account types and beneficiary exclusion rules."""
    middle_names: NotRequired[str]
    r"""Non-primary names representing a natural person; Name attributed to a person other than \"Given\" and \"Family\" names."""
    name: NotRequired[str]
    r"""The name field Format: legalNaturalPersons/{legalNaturalPerson}"""
    name_suffix: NotRequired[PartyNameSuffix]
    r"""The suffix of a natural person; A suffix in a name is any part of the name that comes after the last name"""
    natural_person_fdd: NotRequired[Nullable[PartyNaturalPersonFddTypedDict]]
    r"""Foreign Due Diligence (FDD) information for Legal Natural Person"""
    non_citizen_residency: NotRequired[Nullable[PartyNonCitizenResidencyTypedDict]]
    r"""Facilitates non-citizen lawful US residents to open domestic accounts"""
    personal_address: NotRequired[Nullable[PartyPersonalAddressTypedDict]]
    r"""The legal street number and street name for an account Party. Required fields within the `personal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """
    politically_exposed_immediate_family_names: NotRequired[List[str]]
    r"""A Party's self-disclosed list of names representing family members who are politically exposed."""
    politically_exposed_organization: NotRequired[str]
    r"""A Party's self-disclosed list of named politically exposed organizations they are personally associated with."""
    tax_id: NotRequired[str]
    r"""The full U.S. tax ID for a related person; Must be provided with `ITIN` or `SSN` tax ID type"""
    tax_id_last_four: NotRequired[str]
    r"""The last four characters of the related person's tax identifier; Masked/truncated to \"last four\" in most usage contexts to preserve data privacy."""
    tax_id_type: NotRequired[PartyLegalNaturalPersonTaxIDType]
    r"""The nature of the U.S. Tax ID indicated in the related tax_id field; Examples include ITIN, SSN, EIN."""
    tax_profile: NotRequired[Nullable[PartyLegalNaturalPersonTaxProfileTypedDict]]
    r"""Tax-related attributes at the for the account; A tax profile with taxpayer attributes is located on the legal_natural_person or legal_entity objects elsewhere on the account record."""


class PartyLegalNaturalPerson(BaseModel):
    r"""Legal natural person."""

    accredited_investor: Optional[bool] = None
    r"""Indicates whether the person is an accredited investor"""

    adviser: Optional[bool] = None
    r"""Indicates whether the person is an adviser"""

    birth_date: OptionalNullable[PartyBirthDate] = UNSET
    r"""The legal day, month, and year of birth for a natural person."""

    citizenship_countries: Optional[List[str]] = None
    r"""This is used for tax (treaty) and country block list considerations Maximum list of two 2-char CLDR Code citizenship countries, e.g. US, CA"""

    control_person_company_symbols: Optional[str] = None
    r"""A list of ticker symbols in which the underlying person is a control person; control persons are defined as having significant influence over a company’s management and operations, typically through ownership of a large percentage of the company’s voting stock or through positions on the company’s board of directors or executive team"""

    correspondent_employee: Optional[bool] = None
    r"""Indicates the related owner record is an employee of the clearing broker's correspondent customer."""

    correspondent_id: Optional[str] = None
    r"""A unique identifier referencing a Correspondent; A Client may have several operating Correspondents within its purview."""

    custodian_employee: Optional[bool] = None
    r"""A flag to indicate whether this person is an employee of the correspondent."""

    death_date: OptionalNullable[PartyDeathDate] = UNSET
    r"""The day, month, and year of death of a legal natural person"""

    doing_business_as: Optional[List[str]] = None
    r"""DBA (Doing Business As) names. Can list up to 5 associated with the Legal Natural Person"""

    employment: OptionalNullable[PartyEmployment] = UNSET
    r"""Object containing information pertaining to a investor's current employer including the name, address, and duration of employment."""

    family_name: Optional[str] = None
    r"""Family name of a natural person."""

    finra_associated_entity: Optional[str] = None
    r"""The name of the FINRA-associated entity the underlying natural person is affiliated with."""

    foreign_identification: OptionalNullable[PartyForeignIdentification] = UNSET
    r"""Foreign identification. Must be provided if the person does not have a U.S. tax ID"""

    given_name: Optional[str] = None
    r"""The given name of a natural person; Conventionally known as 'first name' in most English-speaking countries."""

    global_person_id: Optional[str] = None
    r"""Globally Unique identifier for a legal natural person"""

    identity_verification_result: OptionalNullable[
        PartyIdentityVerificationResult
    ] = UNSET
    r"""Third-party data result used to verify the identity of an introduced investor. If the client identity_verification_model is PROVIDED_BY_CLIENT, this field is required"""

    institutional_customer: Optional[bool] = None
    r"""Indicates whether the person is an institutional customer"""

    investigation_id: Optional[str] = None
    r"""Investigation id relating to the Customer Identification Program (CIP) and Customer Due Diligence (CDD)."""

    large_trader: OptionalNullable[PartyLegalNaturalPersonLargeTrader] = UNSET
    r"""Indicates if the person is recognized as a \"Large Trader\" by the SEC."""

    legal_natural_person_id: Optional[str] = None
    r"""A system-generated unique identifier referencing a single natural person; Used to access the record after creation."""

    marital_status: Annotated[
        Optional[PartyMaritalStatus], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The legal marital status of an account-holder; Used in combination with state of domicile to determine qualification for account types and beneficiary exclusion rules."""

    middle_names: Optional[str] = None
    r"""Non-primary names representing a natural person; Name attributed to a person other than \"Given\" and \"Family\" names."""

    name: Optional[str] = None
    r"""The name field Format: legalNaturalPersons/{legalNaturalPerson}"""

    name_suffix: Annotated[
        Optional[PartyNameSuffix], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The suffix of a natural person; A suffix in a name is any part of the name that comes after the last name"""

    natural_person_fdd: OptionalNullable[PartyNaturalPersonFdd] = UNSET
    r"""Foreign Due Diligence (FDD) information for Legal Natural Person"""

    non_citizen_residency: OptionalNullable[PartyNonCitizenResidency] = UNSET
    r"""Facilitates non-citizen lawful US residents to open domestic accounts"""

    personal_address: OptionalNullable[PartyPersonalAddress] = UNSET
    r"""The legal street number and street name for an account Party. Required fields within the `personal_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    politically_exposed_immediate_family_names: Optional[List[str]] = None
    r"""A Party's self-disclosed list of names representing family members who are politically exposed."""

    politically_exposed_organization: Optional[str] = None
    r"""A Party's self-disclosed list of named politically exposed organizations they are personally associated with."""

    tax_id: Optional[str] = None
    r"""The full U.S. tax ID for a related person; Must be provided with `ITIN` or `SSN` tax ID type"""

    tax_id_last_four: Optional[str] = None
    r"""The last four characters of the related person's tax identifier; Masked/truncated to \"last four\" in most usage contexts to preserve data privacy."""

    tax_id_type: Annotated[
        Optional[PartyLegalNaturalPersonTaxIDType],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""The nature of the U.S. Tax ID indicated in the related tax_id field; Examples include ITIN, SSN, EIN."""

    tax_profile: OptionalNullable[PartyLegalNaturalPersonTaxProfile] = UNSET
    r"""Tax-related attributes at the for the account; A tax profile with taxpayer attributes is located on the legal_natural_person or legal_entity objects elsewhere on the account record."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "accredited_investor",
            "adviser",
            "birth_date",
            "citizenship_countries",
            "control_person_company_symbols",
            "correspondent_employee",
            "correspondent_id",
            "custodian_employee",
            "death_date",
            "doing_business_as",
            "employment",
            "family_name",
            "finra_associated_entity",
            "foreign_identification",
            "given_name",
            "global_person_id",
            "identity_verification_result",
            "institutional_customer",
            "investigation_id",
            "large_trader",
            "legal_natural_person_id",
            "marital_status",
            "middle_names",
            "name",
            "name_suffix",
            "natural_person_fdd",
            "non_citizen_residency",
            "personal_address",
            "politically_exposed_immediate_family_names",
            "politically_exposed_organization",
            "tax_id",
            "tax_id_last_four",
            "tax_id_type",
            "tax_profile",
        ]
        nullable_fields = [
            "birth_date",
            "death_date",
            "employment",
            "foreign_identification",
            "identity_verification_result",
            "large_trader",
            "natural_person_fdd",
            "non_citizen_residency",
            "personal_address",
            "tax_profile",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyMailingAddressTypedDict(TypedDict):
    r"""The object containing data for the purpose of delivery physical mailings to a party; Typically used for statements, account updates, tax documents, and other postal mailings; May also be used as an alternative identity verification address to personalAddress. Required fields within the `mailing_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: NotRequired[List[str]]
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """
    administrative_area: NotRequired[str]
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""
    language_code: NotRequired[str]
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """
    locality: NotRequired[str]
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""
    organization: NotRequired[str]
    r"""Optional. The name of the organization at the address."""
    postal_code: NotRequired[str]
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""
    recipients: NotRequired[List[str]]
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""
    region_code: NotRequired[str]
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""
    revision: NotRequired[int]
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """
    sorting_code: NotRequired[str]
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""
    sublocality: NotRequired[str]
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyMailingAddress(BaseModel):
    r"""The object containing data for the purpose of delivery physical mailings to a party; Typically used for statements, account updates, tax documents, and other postal mailings; May also be used as an alternative identity verification address to personalAddress. Required fields within the `mailing_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    address_lines: Optional[List[str]] = None
    r"""Unstructured address lines describing the lower levels of an address.

    Because values in address_lines do not have type information and may sometimes contain multiple values in a single field (e.g. \"Austin, TX\"), it is important that the line order is clear. The order of address lines should be \"envelope order\" for the country/region of the address. In places where this can vary (e.g. Japan), address_language is used to make it explicit (e.g. \"ja\" for large-to-small ordering and \"ja-Latn\" or \"en\" for small-to-large). This way, the most specific line of an address can be selected based on the language.

    The minimum permitted structural representation of an address consists of a region_code with all remaining information placed in the address_lines. It would be possible to format such an address very approximately without geocoding, but no semantic reasoning could be made about any of the address components until it was at least partially resolved.

    Creating an address only containing a region_code and address_lines, and then geocoding is the recommended way to handle completely unstructured addresses (as opposed to guessing which parts of the address should be localities or administrative areas).
    """

    administrative_area: Optional[str] = None
    r"""Optional. Highest administrative subdivision which is used for postal addresses of a country or region. For example, this can be a state, a province, an oblast, or a prefecture. Specifically, for Spain this is the province and not the autonomous community (e.g. \"Barcelona\" and not \"Catalonia\"). Many countries don't use an administrative area in postal addresses. E.g. in Switzerland this should be left unpopulated."""

    language_code: Optional[str] = None
    r"""Optional. BCP-47 language code of the contents of this address (if known). This is often the UI language of the input form or is expected to match one of the languages used in the address' country/region, or their transliterated equivalents. This can affect formatting in certain countries, but is not critical to the correctness of the data and will never affect any validation or other non-formatting related operations.

    If this value is not known, it should be omitted (rather than specifying a possibly incorrect default).

    Examples: \"zh-Hant\", \"ja\", \"ja-Latn\", \"en\".
    """

    locality: Optional[str] = None
    r"""Optional. Generally refers to the city/town portion of the address. Examples: US city, IT comune, UK post town. In regions of the world where localities are not well defined or do not fit into this structure well, leave locality empty and use address_lines."""

    organization: Optional[str] = None
    r"""Optional. The name of the organization at the address."""

    postal_code: Optional[str] = None
    r"""Optional. Postal code of the address. Not all countries use or require postal codes to be present, but where they are used, they may trigger additional validation with other parts of the address (e.g. state/zip validation in the U.S.A.)."""

    recipients: Optional[List[str]] = None
    r"""Optional. The recipient at the address. This field may, under certain circumstances, contain multiline information. For example, it might contain \"care of\" information."""

    region_code: Optional[str] = None
    r"""Required. CLDR region code of the country/region of the address. This is never inferred and it is up to the user to ensure the value is correct. See http://cldr.unicode.org/ and http://www.unicode.org/cldr/charts/30/supplemental/territory_information.html for details. Example: \"CH\" for Switzerland."""

    revision: Optional[int] = None
    r"""The schema revision of the `PostalAddress`. This must be set to 0, which is the latest revision.

    All new revisions **must** be backward compatible with old revisions.
    """

    sorting_code: Optional[str] = None
    r"""Optional. Additional, country-specific, sorting code. This is not used in most regions. Where it is used, the value is either a string like \"CEDEX\", optionally followed by a number (e.g. \"CEDEX 7\"), or just a number alone, representing the \"sector code\" (Jamaica), \"delivery area indicator\" (Malawi) or \"post office indicator\" (e.g. Côte d'Ivoire)."""

    sublocality: Optional[str] = None
    r"""Optional. Sublocality of the address. For example, this can be neighborhoods, boroughs, districts."""


class PartyShortCodeTypedDict(TypedDict):
    r"""A short code.

    Reference(s):
    - https://en.wikipedia.org/wiki/Short_code
    """

    number: NotRequired[str]
    r"""Required. The short code digits, without a leading plus ('+') or country calling code, e.g. \"611\"."""
    region_code: NotRequired[str]
    r"""Required. The BCP-47 region code of the location where calls to this short code can be made, such as \"US\" and \"BB\".

    Reference(s):
    - http://www.unicode.org/reports/tr35/#unicode_region_subtag
    """


class PartyShortCode(BaseModel):
    r"""A short code.

    Reference(s):
    - https://en.wikipedia.org/wiki/Short_code
    """

    number: Optional[str] = None
    r"""Required. The short code digits, without a leading plus ('+') or country calling code, e.g. \"611\"."""

    region_code: Optional[str] = None
    r"""Required. The BCP-47 region code of the location where calls to this short code can be made, such as \"US\" and \"BB\".

    Reference(s):
    - http://www.unicode.org/reports/tr35/#unicode_region_subtag
    """


class PartyPhoneNumberTypedDict(TypedDict):
    r"""The phone number for a party. Lives on the party record in the context of the account and does not commute to other accounts held by/for the person."""

    e164_number: NotRequired[str]
    r"""The phone number, represented as a leading plus sign ('+'), followed by a phone number that uses a relaxed ITU E.164 format consisting of the country calling code (1 to 3 digits) and the subscriber number, with no additional spaces or formatting, e.g.: - correct: \"+15552220123\" - incorrect: \"+1 (555) 222-01234 x123\".

    The ITU E.164 format limits the latter to 12 digits, but in practice not all countries respect that, so we relax that restriction here. National-only numbers are not allowed.

    References: - https://www.itu.int/rec/T-REC-E.164-201011-I - https://en.wikipedia.org/wiki/E.164. - https://en.wikipedia.org/wiki/List_of_country_calling_codes
    """
    extension: NotRequired[str]
    r"""The phone number's extension. The extension is not standardized in ITU recommendations, except for being defined as a series of numbers with a maximum length of 40 digits. Other than digits, some other dialing characters such as ',' (indicating a wait) or '#' may be stored here.

    Note that no regions currently use extensions with short codes, so this field is normally only set in conjunction with an E.164 number. It is held separately from the E.164 number to allow for short code extensions in the future.
    """
    short_code: NotRequired[Nullable[PartyShortCodeTypedDict]]
    r"""A short code.

    Reference(s):
    - https://en.wikipedia.org/wiki/Short_code
    """


class PartyPhoneNumber(BaseModel):
    r"""The phone number for a party. Lives on the party record in the context of the account and does not commute to other accounts held by/for the person."""

    e164_number: Optional[str] = None
    r"""The phone number, represented as a leading plus sign ('+'), followed by a phone number that uses a relaxed ITU E.164 format consisting of the country calling code (1 to 3 digits) and the subscriber number, with no additional spaces or formatting, e.g.: - correct: \"+15552220123\" - incorrect: \"+1 (555) 222-01234 x123\".

    The ITU E.164 format limits the latter to 12 digits, but in practice not all countries respect that, so we relax that restriction here. National-only numbers are not allowed.

    References: - https://www.itu.int/rec/T-REC-E.164-201011-I - https://en.wikipedia.org/wiki/E.164. - https://en.wikipedia.org/wiki/List_of_country_calling_codes
    """

    extension: Optional[str] = None
    r"""The phone number's extension. The extension is not standardized in ITU recommendations, except for being defined as a series of numbers with a maximum length of 40 digits. Other than digits, some other dialing characters such as ',' (indicating a wait) or '#' may be stored here.

    Note that no regions currently use extensions with short codes, so this field is normally only set in conjunction with an E.164 number. It is held separately from the E.164 number to allow for short code extensions in the future.
    """

    short_code: OptionalNullable[PartyShortCode] = UNSET
    r"""A short code.

    Reference(s):
    - https://en.wikipedia.org/wiki/Short_code
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["e164_number", "extension", "short_code"]
        nullable_fields = ["short_code"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class PartyProspectusDeliveryPreference(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Delivery method instruction for prospectuses for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    DELIVERY_PREFERENCE_UNSPECIFIED = "DELIVERY_PREFERENCE_UNSPECIFIED"
    DIGITAL = "DIGITAL"
    PHYSICAL = "PHYSICAL"
    SUPPRESS = "SUPPRESS"


class PartyProxyDeliveryPreference(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Delivery method instruction for proxy voting for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    DELIVERY_PREFERENCE_UNSPECIFIED = "DELIVERY_PREFERENCE_UNSPECIFIED"
    DIGITAL = "DIGITAL"
    PHYSICAL = "PHYSICAL"
    SUPPRESS = "SUPPRESS"


class PartyRelationType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Conveys how a person is related to account; Located on each account Party record; Examples are `PRIMARY_OWNER`, `JOINT_OWNER`, `EXECUTOR`, etc."""

    PARTY_RELATION_TYPE_UNSPECIFIED = "PARTY_RELATION_TYPE_UNSPECIFIED"
    PRIMARY_OWNER = "PRIMARY_OWNER"
    JOINT_OWNER = "JOINT_OWNER"
    CUSTODIAN = "CUSTODIAN"
    GUARDIAN_CONSERVATOR = "GUARDIAN_CONSERVATOR"
    POWER_OF_ATTORNEY = "POWER_OF_ATTORNEY"
    EXECUTOR = "EXECUTOR"
    AUTHORIZED_SIGNER = "AUTHORIZED_SIGNER"
    BENEFICIAL_OWNER = "BENEFICIAL_OWNER"
    CONTROL_PERSON = "CONTROL_PERSON"
    AUTHORIZED_REPRESENTATIVE = "AUTHORIZED_REPRESENTATIVE"
    TRUSTEE = "TRUSTEE"
    AUTH_TRUSTEE_REP = "AUTH_TRUSTEE_REP"


class PartyStatementDeliveryPreference(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Delivery method instruction for account statements for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    DELIVERY_PREFERENCE_UNSPECIFIED = "DELIVERY_PREFERENCE_UNSPECIFIED"
    DIGITAL = "DIGITAL"
    PHYSICAL = "PHYSICAL"
    SUPPRESS = "SUPPRESS"


class PartyTaxDocumentDeliveryPreference(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Delivery method instruction for tax documents for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated; Per regulation, selected tax forms will be mailed by regulation regardless of this setting"""

    DELIVERY_PREFERENCE_UNSPECIFIED = "DELIVERY_PREFERENCE_UNSPECIFIED"
    DIGITAL = "DIGITAL"
    PHYSICAL = "PHYSICAL"
    SUPPRESS = "SUPPRESS"


class PartyTradeConfirmationDeliveryPreference(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Delivery method instruction for trade confirmations for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    DELIVERY_PREFERENCE_UNSPECIFIED = "DELIVERY_PREFERENCE_UNSPECIFIED"
    DIGITAL = "DIGITAL"
    PHYSICAL = "PHYSICAL"
    SUPPRESS = "SUPPRESS"


class PartyTypedDict(TypedDict):
    r"""A single record representing an owner or manager of an Account. Contains fully populated Party Identity object."""

    email_address: NotRequired[str]
    r"""An email address indicated for account communications."""
    legal_entity: NotRequired[Nullable[PartyLegalEntityTypedDict]]
    r"""Legal entity."""
    legal_natural_person: NotRequired[Nullable[PartyLegalNaturalPersonTypedDict]]
    r"""Legal natural person."""
    mailing_address: NotRequired[Nullable[PartyMailingAddressTypedDict]]
    r"""The object containing data for the purpose of delivery physical mailings to a party; Typically used for statements, account updates, tax documents, and other postal mailings; May also be used as an alternative identity verification address to personalAddress. Required fields within the `mailing_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """
    name: NotRequired[str]
    r"""The name field Format: {parent=account/*}/{name=party/*}"""
    party_id: NotRequired[str]
    r"""A system-generated unique identifier referencing a single owner or control person on an account; A Party contains account-specific information about a person whereas inside the Party is a reference to a reusable instance of a Person `legal_natural_person` or `legal_entity` which contains non-changing information about these persons; Used to access the record after creation"""
    phone_number: NotRequired[Nullable[PartyPhoneNumberTypedDict]]
    r"""The phone number for a party. Lives on the party record in the context of the account and does not commute to other accounts held by/for the person."""
    prospectus_delivery_preference: NotRequired[PartyProspectusDeliveryPreference]
    r"""Delivery method instruction for prospectuses for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""
    proxy_delivery_preference: NotRequired[PartyProxyDeliveryPreference]
    r"""Delivery method instruction for proxy voting for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""
    relation_type: NotRequired[PartyRelationType]
    r"""Conveys how a person is related to account; Located on each account Party record; Examples are `PRIMARY_OWNER`, `JOINT_OWNER`, `EXECUTOR`, etc."""
    statement_delivery_preference: NotRequired[PartyStatementDeliveryPreference]
    r"""Delivery method instruction for account statements for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""
    tax_document_delivery_preference: NotRequired[PartyTaxDocumentDeliveryPreference]
    r"""Delivery method instruction for tax documents for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated; Per regulation, selected tax forms will be mailed by regulation regardless of this setting"""
    trade_confirmation_delivery_preference: NotRequired[
        PartyTradeConfirmationDeliveryPreference
    ]
    r"""Delivery method instruction for trade confirmations for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""


class Party(BaseModel):
    r"""A single record representing an owner or manager of an Account. Contains fully populated Party Identity object."""

    email_address: Optional[str] = None
    r"""An email address indicated for account communications."""

    legal_entity: OptionalNullable[PartyLegalEntity] = UNSET
    r"""Legal entity."""

    legal_natural_person: OptionalNullable[PartyLegalNaturalPerson] = UNSET
    r"""Legal natural person."""

    mailing_address: OptionalNullable[PartyMailingAddress] = UNSET
    r"""The object containing data for the purpose of delivery physical mailings to a party; Typically used for statements, account updates, tax documents, and other postal mailings; May also be used as an alternative identity verification address to personalAddress. Required fields within the `mailing_address` object include:
    - `administrative_area`
    - `region_code` - 2 character CLDR Code
    - `postal_code`
    - `locality`
    - `address_lines` - max 5 lines
    """

    name: Optional[str] = None
    r"""The name field Format: {parent=account/*}/{name=party/*}"""

    party_id: Optional[str] = None
    r"""A system-generated unique identifier referencing a single owner or control person on an account; A Party contains account-specific information about a person whereas inside the Party is a reference to a reusable instance of a Person `legal_natural_person` or `legal_entity` which contains non-changing information about these persons; Used to access the record after creation"""

    phone_number: OptionalNullable[PartyPhoneNumber] = UNSET
    r"""The phone number for a party. Lives on the party record in the context of the account and does not commute to other accounts held by/for the person."""

    prospectus_delivery_preference: Annotated[
        Optional[PartyProspectusDeliveryPreference],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Delivery method instruction for prospectuses for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    proxy_delivery_preference: Annotated[
        Optional[PartyProxyDeliveryPreference],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Delivery method instruction for proxy voting for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    relation_type: Annotated[
        Optional[PartyRelationType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Conveys how a person is related to account; Located on each account Party record; Examples are `PRIMARY_OWNER`, `JOINT_OWNER`, `EXECUTOR`, etc."""

    statement_delivery_preference: Annotated[
        Optional[PartyStatementDeliveryPreference],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Delivery method instruction for account statements for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    tax_document_delivery_preference: Annotated[
        Optional[PartyTaxDocumentDeliveryPreference],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Delivery method instruction for tax documents for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated; Per regulation, selected tax forms will be mailed by regulation regardless of this setting"""

    trade_confirmation_delivery_preference: Annotated[
        Optional[PartyTradeConfirmationDeliveryPreference],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Delivery method instruction for trade confirmations for a given Party record; Can be `DIGITAL`, `PHYSICAL`, `SUPPRESS`; Defaults to `DIGITAL` on account creation but may be updated"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "email_address",
            "legal_entity",
            "legal_natural_person",
            "mailing_address",
            "name",
            "party_id",
            "phone_number",
            "prospectus_delivery_preference",
            "proxy_delivery_preference",
            "relation_type",
            "statement_delivery_preference",
            "tax_document_delivery_preference",
            "trade_confirmation_delivery_preference",
        ]
        nullable_fields = [
            "legal_entity",
            "legal_natural_person",
            "mailing_address",
            "phone_number",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
