"""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 datetime import datetime
from enum import Enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Any, Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class IctWithdrawalAmountTypedDict(TypedDict):
    r"""The amount of the transfer being withdrawn from the customer's account in USD. A value should not be provided if the withdrawal is a full disbursement."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalAmount(BaseModel):
    r"""The amount of the transfer being withdrawn from the customer's account in USD. A value should not be provided if the withdrawal is a full disbursement."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalProgram(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The name of the program that the ICT withdrawal is associated with."""

    ICT_PROGRAM_UNSPECIFIED = "ICT_PROGRAM_UNSPECIFIED"
    BROKER_PARTNER = "BROKER_PARTNER"
    DEPOSIT_ONLY = "DEPOSIT_ONLY"
    BANKING_PARTNER = "BANKING_PARTNER"
    MONEY_TRANSMITTER = "MONEY_TRANSMITTER"
    WITHDRAWAL_ONLY = "WITHDRAWAL_ONLY"
    DIGITAL_PARTNER = "DIGITAL_PARTNER"


class IctWithdrawalRetirementDistributionAmountTypedDict(TypedDict):
    r"""Fixed USD amount to withhold for taxes."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalRetirementDistributionAmount(BaseModel):
    r"""Fixed USD amount to withhold for taxes."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalPercentageTypedDict(TypedDict):
    r"""Percentage of total disbursement amount to withhold for taxes."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalPercentage(BaseModel):
    r"""Percentage of total disbursement amount to withhold for taxes."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalFederalTaxWithholdingTypedDict(TypedDict):
    r"""The federal tax withholding."""

    amount: NotRequired[Nullable[IctWithdrawalRetirementDistributionAmountTypedDict]]
    r"""Fixed USD amount to withhold for taxes."""
    percentage: NotRequired[Nullable[IctWithdrawalPercentageTypedDict]]
    r"""Percentage of total disbursement amount to withhold for taxes."""


class IctWithdrawalFederalTaxWithholding(BaseModel):
    r"""The federal tax withholding."""

    amount: OptionalNullable[IctWithdrawalRetirementDistributionAmount] = UNSET
    r"""Fixed USD amount to withhold for taxes."""

    percentage: OptionalNullable[IctWithdrawalPercentage] = UNSET
    r"""Percentage of total disbursement amount to withhold for taxes."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["amount", "percentage"]
        nullable_fields = ["amount", "percentage"]
        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 IctWithdrawalRetirementDistributionStateTaxWithholdingAmountTypedDict(TypedDict):
    r"""Fixed USD amount to withhold for taxes."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalRetirementDistributionStateTaxWithholdingAmount(BaseModel):
    r"""Fixed USD amount to withhold for taxes."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalRetirementDistributionPercentageTypedDict(TypedDict):
    r"""Percentage of total disbursement amount to withhold for taxes."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalRetirementDistributionPercentage(BaseModel):
    r"""Percentage of total disbursement amount to withhold for taxes."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class IctWithdrawalStateTaxWithholdingTypedDict(TypedDict):
    r"""The state tax withholding."""

    amount: NotRequired[
        Nullable[IctWithdrawalRetirementDistributionStateTaxWithholdingAmountTypedDict]
    ]
    r"""Fixed USD amount to withhold for taxes."""
    percentage: NotRequired[
        Nullable[IctWithdrawalRetirementDistributionPercentageTypedDict]
    ]
    r"""Percentage of total disbursement amount to withhold for taxes."""


class IctWithdrawalStateTaxWithholding(BaseModel):
    r"""The state tax withholding."""

    amount: OptionalNullable[
        IctWithdrawalRetirementDistributionStateTaxWithholdingAmount
    ] = UNSET
    r"""Fixed USD amount to withhold for taxes."""

    percentage: OptionalNullable[IctWithdrawalRetirementDistributionPercentage] = UNSET
    r"""Percentage of total disbursement amount to withhold for taxes."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["amount", "percentage"]
        nullable_fields = ["amount", "percentage"]
        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 IctWithdrawalType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The type of retirement distribution."""

    TYPE_UNSPECIFIED = "TYPE_UNSPECIFIED"
    NORMAL = "NORMAL"
    DISABILITY = "DISABILITY"
    SOSEPP = "SOSEPP"
    PREMATURE = "PREMATURE"
    DEATH = "DEATH"
    EXCESS_CONTRIBUTION_REMOVAL_BEFORE_TAX_DEADLINE = (
        "EXCESS_CONTRIBUTION_REMOVAL_BEFORE_TAX_DEADLINE"
    )
    EXCESS_CONTRIBUTION_REMOVAL_AFTER_TAX_DEADLINE = (
        "EXCESS_CONTRIBUTION_REMOVAL_AFTER_TAX_DEADLINE"
    )
    ROLLOVER_TO_QUALIFIED_PLAN = "ROLLOVER_TO_QUALIFIED_PLAN"
    ROLLOVER_TO_IRA = "ROLLOVER_TO_IRA"
    DISTRIBUTION_TRANSFER = "DISTRIBUTION_TRANSFER"
    RECHARACTERIZATION_PRIOR_YEAR = "RECHARACTERIZATION_PRIOR_YEAR"
    RECHARACTERIZATION_CURRENT_YEAR = "RECHARACTERIZATION_CURRENT_YEAR"
    DISTRIBUTION_CONVERSION = "DISTRIBUTION_CONVERSION"
    MANAGEMENT_FEE = "MANAGEMENT_FEE"
    PLAN_LOAN_401_K = "PLAN_LOAN_401K"
    PREMATURE_SIMPLE_IRA_LESS_THAN_2_YEARS = "PREMATURE_SIMPLE_IRA_LESS_THAN_2_YEARS"
    NORMAL_ROTH_IRA_GREATER_THAN_5_YEARS = "NORMAL_ROTH_IRA_GREATER_THAN_5_YEARS"


class IctWithdrawalRetirementDistributionTypedDict(TypedDict):
    r"""Retirement distribution details for withdrawal from retirement account"""

    federal_tax_withholding: NotRequired[
        Nullable[IctWithdrawalFederalTaxWithholdingTypedDict]
    ]
    r"""The federal tax withholding."""
    receiving_institution: NotRequired[str]
    r"""The institution receiving retirement funds when performing a transfer to an identical retirement account type at a different financial institution. This is required for check and wire withdrawals because we can't always identify the institution using the transfer instructions. For cash journals this value will default to \"Apex Clearing\", regardless of what is passed in here"""
    state_tax_withholding: NotRequired[
        Nullable[IctWithdrawalStateTaxWithholdingTypedDict]
    ]
    r"""The state tax withholding."""
    state_withholding_waiver: NotRequired[bool]
    r"""Whether or not this distribution has a state withholding waiver."""
    tax_year: NotRequired[int]
    r"""Tax year for which the distribution is applied."""
    type: NotRequired[IctWithdrawalType]
    r"""The type of retirement distribution."""


class IctWithdrawalRetirementDistribution(BaseModel):
    r"""Retirement distribution details for withdrawal from retirement account"""

    federal_tax_withholding: OptionalNullable[
        IctWithdrawalFederalTaxWithholding
    ] = UNSET
    r"""The federal tax withholding."""

    receiving_institution: Optional[str] = None
    r"""The institution receiving retirement funds when performing a transfer to an identical retirement account type at a different financial institution. This is required for check and wire withdrawals because we can't always identify the institution using the transfer instructions. For cash journals this value will default to \"Apex Clearing\", regardless of what is passed in here"""

    state_tax_withholding: OptionalNullable[IctWithdrawalStateTaxWithholding] = UNSET
    r"""The state tax withholding."""

    state_withholding_waiver: Optional[bool] = None
    r"""Whether or not this distribution has a state withholding waiver."""

    tax_year: Optional[int] = None
    r"""Tax year for which the distribution is applied."""

    type: Annotated[
        Optional[IctWithdrawalType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The type of retirement distribution."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "federal_tax_withholding",
            "receiving_institution",
            "state_tax_withholding",
            "state_withholding_waiver",
            "tax_year",
            "type",
        ]
        nullable_fields = ["federal_tax_withholding", "state_tax_withholding"]
        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 IctWithdrawalState(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The high level state of a transfer, one of:
    - `PROCESSING` - The transfer is being processed and will be posted if successful.
    - `PENDING_REVIEW` - The transfer is pending review and will continue processing if approved.
    - `POSTED` - The transfer has been posted to the ledger and will be completed at the end of the processing window if not canceled first.
    - `COMPLETED` - The transfer has been batched and completed.
    - `REJECTED` - The transfer was rejected.
    - `CANCELED` - The transfer was canceled.
    - `RETURNED` - The transfer was returned.
    - `POSTPONED` - The transfer is postponed and will resume processing during the next processing window.
    """

    STATE_UNSPECIFIED = "STATE_UNSPECIFIED"
    PROCESSING = "PROCESSING"
    PENDING_REVIEW = "PENDING_REVIEW"
    POSTED = "POSTED"
    COMPLETED = "COMPLETED"
    REJECTED = "REJECTED"
    CANCELED = "CANCELED"
    RETURNED = "RETURNED"
    POSTPONED = "POSTPONED"


class IctWithdrawalTransferStateTypedDict(TypedDict):
    r"""The state of the ICT withdrawal"""

    actor: NotRequired[str]
    r"""The user or service that triggered the state update."""
    message: NotRequired[str]
    r"""Additional description of the transfer state."""
    metadata: NotRequired[Nullable[Dict[str, Any]]]
    r"""Additional metadata relating to the transfer state. Included data depends on the state, e.g.:
    - Rejection reasons are included when the `state` is `REJECTED`
    - Reason and comment are included when `state` is `CANCELED`
    """
    state: NotRequired[IctWithdrawalState]
    r"""The high level state of a transfer, one of:
    - `PROCESSING` - The transfer is being processed and will be posted if successful.
    - `PENDING_REVIEW` - The transfer is pending review and will continue processing if approved.
    - `POSTED` - The transfer has been posted to the ledger and will be completed at the end of the processing window if not canceled first.
    - `COMPLETED` - The transfer has been batched and completed.
    - `REJECTED` - The transfer was rejected.
    - `CANCELED` - The transfer was canceled.
    - `RETURNED` - The transfer was returned.
    - `POSTPONED` - The transfer is postponed and will resume processing during the next processing window.
    """
    update_time: NotRequired[Nullable[datetime]]
    r"""The time of the state update."""


class IctWithdrawalTransferState(BaseModel):
    r"""The state of the ICT withdrawal"""

    actor: Optional[str] = None
    r"""The user or service that triggered the state update."""

    message: Optional[str] = None
    r"""Additional description of the transfer state."""

    metadata: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Additional metadata relating to the transfer state. Included data depends on the state, e.g.:
    - Rejection reasons are included when the `state` is `REJECTED`
    - Reason and comment are included when `state` is `CANCELED`
    """

    state: Annotated[
        Optional[IctWithdrawalState], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The high level state of a transfer, one of:
    - `PROCESSING` - The transfer is being processed and will be posted if successful.
    - `PENDING_REVIEW` - The transfer is pending review and will continue processing if approved.
    - `POSTED` - The transfer has been posted to the ledger and will be completed at the end of the processing window if not canceled first.
    - `COMPLETED` - The transfer has been batched and completed.
    - `REJECTED` - The transfer was rejected.
    - `CANCELED` - The transfer was canceled.
    - `RETURNED` - The transfer was returned.
    - `POSTPONED` - The transfer is postponed and will resume processing during the next processing window.
    """

    update_time: OptionalNullable[datetime] = UNSET
    r"""The time of the state update."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["actor", "message", "metadata", "state", "update_time"]
        nullable_fields = ["metadata", "update_time"]
        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 IctWithdrawalAddressTypedDict(TypedDict):
    r"""The address of the entity"""

    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 IctWithdrawalAddress(BaseModel):
    r"""The address of the entity"""

    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 IctWithdrawalEntityOriginatingPartyTypedDict(TypedDict):
    r"""An entity originating party"""

    address: NotRequired[Nullable[IctWithdrawalAddressTypedDict]]
    r"""The address of the entity"""
    tax_id: NotRequired[str]
    r"""The tax identification number of the entity"""
    title: NotRequired[str]
    r"""The name of the entity"""


class IctWithdrawalEntityOriginatingParty(BaseModel):
    r"""An entity originating party"""

    address: OptionalNullable[IctWithdrawalAddress] = UNSET
    r"""The address of the entity"""

    tax_id: Optional[str] = None
    r"""The tax identification number of the entity"""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["address", "tax_id", "title"]
        nullable_fields = ["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 IctWithdrawalTravelRuleAddressTypedDict(TypedDict):
    r"""The address of the entity"""

    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 IctWithdrawalTravelRuleAddress(BaseModel):
    r"""The address of the entity"""

    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 IctWithdrawalEntityRecipientPartyTypedDict(TypedDict):
    r"""An entity originating party"""

    address: NotRequired[Nullable[IctWithdrawalTravelRuleAddressTypedDict]]
    r"""The address of the entity"""
    tax_id: NotRequired[str]
    r"""The tax identification number of the entity"""
    title: NotRequired[str]
    r"""The name of the entity"""


class IctWithdrawalEntityRecipientParty(BaseModel):
    r"""An entity originating party"""

    address: OptionalNullable[IctWithdrawalTravelRuleAddress] = UNSET
    r"""The address of the entity"""

    tax_id: Optional[str] = None
    r"""The tax identification number of the entity"""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["address", "tax_id", "title"]
        nullable_fields = ["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 IctWithdrawalTravelRuleIndividualOriginatingPartyAddressTypedDict(TypedDict):
    r"""The address of the party"""

    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 IctWithdrawalTravelRuleIndividualOriginatingPartyAddress(BaseModel):
    r"""The address of the party"""

    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 IctWithdrawalIndividualOriginatingPartyTypedDict(TypedDict):
    r"""An individual originating party"""

    address: NotRequired[
        Nullable[IctWithdrawalTravelRuleIndividualOriginatingPartyAddressTypedDict]
    ]
    r"""The address of the party"""
    family_name: NotRequired[str]
    r"""The last name of the party"""
    given_names: NotRequired[List[str]]
    r"""The first name of the party as well as any non-primary given names (e.g. middle names)"""


class IctWithdrawalIndividualOriginatingParty(BaseModel):
    r"""An individual originating party"""

    address: OptionalNullable[
        IctWithdrawalTravelRuleIndividualOriginatingPartyAddress
    ] = UNSET
    r"""The address of the party"""

    family_name: Optional[str] = None
    r"""The last name of the party"""

    given_names: Optional[List[str]] = None
    r"""The first name of the party as well as any non-primary given names (e.g. middle names)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["address", "family_name", "given_names"]
        nullable_fields = ["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 IctWithdrawalTravelRuleIndividualRecipientPartyAddressTypedDict(TypedDict):
    r"""The address of the party"""

    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 IctWithdrawalTravelRuleIndividualRecipientPartyAddress(BaseModel):
    r"""The address of the party"""

    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 IctWithdrawalIndividualRecipientPartyTypedDict(TypedDict):
    r"""An individual recipient party"""

    address: NotRequired[
        Nullable[IctWithdrawalTravelRuleIndividualRecipientPartyAddressTypedDict]
    ]
    r"""The address of the party"""
    family_name: NotRequired[str]
    r"""The last name of the party"""
    given_names: NotRequired[List[str]]
    r"""The first name of the party as well as any non-primary given names (e.g. middle names)"""


class IctWithdrawalIndividualRecipientParty(BaseModel):
    r"""An individual recipient party"""

    address: OptionalNullable[
        IctWithdrawalTravelRuleIndividualRecipientPartyAddress
    ] = UNSET
    r"""The address of the party"""

    family_name: Optional[str] = None
    r"""The last name of the party"""

    given_names: Optional[List[str]] = None
    r"""The first name of the party as well as any non-primary given names (e.g. middle names)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["address", "family_name", "given_names"]
        nullable_fields = ["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 IctWithdrawalOriginatingInstitutionTypedDict(TypedDict):
    r"""The name and account id of institution sourcing the funds. Always 'Apex Clearing' and investor account id for ICT withdrawals;"""

    account_id: NotRequired[str]
    r"""Account id at institution"""
    title: NotRequired[str]
    r"""Name of the institution"""


class IctWithdrawalOriginatingInstitution(BaseModel):
    r"""The name and account id of institution sourcing the funds. Always 'Apex Clearing' and investor account id for ICT withdrawals;"""

    account_id: Optional[str] = None
    r"""Account id at institution"""

    title: Optional[str] = None
    r"""Name of the institution"""


class IctWithdrawalRecipientInstitutionTypedDict(TypedDict):
    r"""The name and account id of the external financial institution that will take receipt of the funds."""

    account_id: NotRequired[str]
    r"""Account id at institution"""
    title: NotRequired[str]
    r"""Name of the institution"""


class IctWithdrawalRecipientInstitution(BaseModel):
    r"""The name and account id of the external financial institution that will take receipt of the funds."""

    account_id: Optional[str] = None
    r"""Account id at institution"""

    title: Optional[str] = None
    r"""Name of the institution"""


class IctWithdrawalTravelRuleTypedDict(TypedDict):
    r"""The travel rule information for the ICT withdrawal"""

    entity_originating_party: NotRequired[
        Nullable[IctWithdrawalEntityOriginatingPartyTypedDict]
    ]
    r"""An entity originating party"""
    entity_recipient_party: NotRequired[
        Nullable[IctWithdrawalEntityRecipientPartyTypedDict]
    ]
    r"""An entity originating party"""
    individual_originating_party: NotRequired[
        Nullable[IctWithdrawalIndividualOriginatingPartyTypedDict]
    ]
    r"""An individual originating party"""
    individual_recipient_party: NotRequired[
        Nullable[IctWithdrawalIndividualRecipientPartyTypedDict]
    ]
    r"""An individual recipient party"""
    originating_institution: NotRequired[
        Nullable[IctWithdrawalOriginatingInstitutionTypedDict]
    ]
    r"""The name and account id of institution sourcing the funds. Always 'Apex Clearing' and investor account id for ICT withdrawals;"""
    recipient_institution: NotRequired[
        Nullable[IctWithdrawalRecipientInstitutionTypedDict]
    ]
    r"""The name and account id of the external financial institution that will take receipt of the funds."""


class IctWithdrawalTravelRule(BaseModel):
    r"""The travel rule information for the ICT withdrawal"""

    entity_originating_party: OptionalNullable[
        IctWithdrawalEntityOriginatingParty
    ] = UNSET
    r"""An entity originating party"""

    entity_recipient_party: OptionalNullable[IctWithdrawalEntityRecipientParty] = UNSET
    r"""An entity originating party"""

    individual_originating_party: OptionalNullable[
        IctWithdrawalIndividualOriginatingParty
    ] = UNSET
    r"""An individual originating party"""

    individual_recipient_party: OptionalNullable[
        IctWithdrawalIndividualRecipientParty
    ] = UNSET
    r"""An individual recipient party"""

    originating_institution: OptionalNullable[
        IctWithdrawalOriginatingInstitution
    ] = UNSET
    r"""The name and account id of institution sourcing the funds. Always 'Apex Clearing' and investor account id for ICT withdrawals;"""

    recipient_institution: OptionalNullable[IctWithdrawalRecipientInstitution] = UNSET
    r"""The name and account id of the external financial institution that will take receipt of the funds."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "entity_originating_party",
            "entity_recipient_party",
            "individual_originating_party",
            "individual_recipient_party",
            "originating_institution",
            "recipient_institution",
        ]
        nullable_fields = [
            "entity_originating_party",
            "entity_recipient_party",
            "individual_originating_party",
            "individual_recipient_party",
            "originating_institution",
            "recipient_institution",
        ]
        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 IctWithdrawalTypedDict(TypedDict):
    r"""An Instant Cash Transfer. Funds are moved from a customer's brokerage account to a configured Firm account."""

    amount: NotRequired[Nullable[IctWithdrawalAmountTypedDict]]
    r"""The amount of the transfer being withdrawn from the customer's account in USD. A value should not be provided if the withdrawal is a full disbursement."""
    client_transfer_id: NotRequired[str]
    r"""External identifier supplied by the API caller. Each request must have a unique pairing of client_transfer_id and account."""
    name: NotRequired[str]
    r"""Full name of the ICT withdrawal resource, which contains account id and ICT withdrawal id"""
    program: NotRequired[IctWithdrawalProgram]
    r"""The name of the program that the ICT withdrawal is associated with."""
    retirement_distribution: NotRequired[
        Nullable[IctWithdrawalRetirementDistributionTypedDict]
    ]
    r"""Retirement distribution details for withdrawal from retirement account"""
    transfer_state: NotRequired[Nullable[IctWithdrawalTransferStateTypedDict]]
    r"""The state of the ICT withdrawal"""
    travel_rule: NotRequired[Nullable[IctWithdrawalTravelRuleTypedDict]]
    r"""The travel rule information for the ICT withdrawal"""


class IctWithdrawal(BaseModel):
    r"""An Instant Cash Transfer. Funds are moved from a customer's brokerage account to a configured Firm account."""

    amount: OptionalNullable[IctWithdrawalAmount] = UNSET
    r"""The amount of the transfer being withdrawn from the customer's account in USD. A value should not be provided if the withdrawal is a full disbursement."""

    client_transfer_id: Optional[str] = None
    r"""External identifier supplied by the API caller. Each request must have a unique pairing of client_transfer_id and account."""

    name: Optional[str] = None
    r"""Full name of the ICT withdrawal resource, which contains account id and ICT withdrawal id"""

    program: Annotated[
        Optional[IctWithdrawalProgram], PlainValidator(validate_open_enum(False))
    ] = None
    r"""The name of the program that the ICT withdrawal is associated with."""

    retirement_distribution: OptionalNullable[
        IctWithdrawalRetirementDistribution
    ] = UNSET
    r"""Retirement distribution details for withdrawal from retirement account"""

    transfer_state: OptionalNullable[IctWithdrawalTransferState] = UNSET
    r"""The state of the ICT withdrawal"""

    travel_rule: OptionalNullable[IctWithdrawalTravelRule] = UNSET
    r"""The travel rule information for the ICT withdrawal"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "amount",
            "client_transfer_id",
            "name",
            "program",
            "retirement_distribution",
            "transfer_state",
            "travel_rule",
        ]
        nullable_fields = [
            "amount",
            "retirement_distribution",
            "transfer_state",
            "travel_rule",
        ]
        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
