"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: a25c5299fa39

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .credit_debit_indicator import CreditDebitIndicator
from .metadata import Metadata, MetadataTypedDict
from .mode import Mode
from .status_history_entry_response import (
    StatusHistoryEntryResponse,
    StatusHistoryEntryResponseTypedDict,
)
from .status_reason_2 import StatusReason2, StatusReason2TypedDict
from .transfer_party import TransferParty, TransferPartyTypedDict
from .transfer_scheme_response import (
    TransferSchemeResponse,
    TransferSchemeResponseTypedDict,
)
from .transfer_status import TransferStatus
from mollie import models
from mollie.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import field_serializer, model_serializer
from typing import List
from typing_extensions import Annotated, NotRequired, TypedDict


class TransferResponseAccountTypedDict(TypedDict):
    r"""The bank account details of the party."""

    iban: str
    r"""The IBAN (International Bank Account Number) of the account holder."""


class TransferResponseAccount(BaseModel):
    r"""The bank account details of the party."""

    iban: str
    r"""The IBAN (International Bank Account Number) of the account holder."""


class DebtorTypedDict(TypedDict):
    r"""The debtor (sender) of the transfer, including their name and account details."""

    full_name: str
    r"""The full name of the account holder."""
    account: TransferResponseAccountTypedDict
    r"""The bank account details of the party."""


class Debtor(BaseModel):
    r"""The debtor (sender) of the transfer, including their name and account details."""

    full_name: Annotated[str, pydantic.Field(alias="fullName")]
    r"""The full name of the account holder."""

    account: TransferResponseAccount
    r"""The bank account details of the party."""


class TransferResponseTypedDict(TypedDict):
    resource: str
    r"""Indicates the response contains a transfer object. Will always contain the string `business-account-transfer`
    for this endpoint.
    """
    id: str
    r"""The identifier uniquely referring to this transfer. Mollie assigns this identifier at transfer creation time."""
    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""
    debtor: DebtorTypedDict
    r"""The debtor (sender) of the transfer, including their name and account details."""
    creditor: TransferPartyTypedDict
    r"""A party involved in the transfer, representing either the debtor (sender) or creditor (recipient).
    Contains the party's name and account details.
    """
    amount: AmountTypedDict
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""
    business_account_transaction_id: str
    r"""The identifier of the corresponding transaction in the business accounts transaction resource."""
    transfer_scheme: TransferSchemeResponseTypedDict
    r"""The scheme, as requested by the client."""
    credit_debit_indicator: CreditDebitIndicator
    r"""Indicates whether the transfer is a credit or debit transaction from the perspective of the account holder."""
    status: TransferStatus
    r"""The status of the transfer."""
    status_history: List[StatusHistoryEntryResponseTypedDict]
    r"""A chronological list of status transitions the transfer has gone through."""
    created_at: str
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""
    description: NotRequired[Nullable[str]]
    r"""A short description of the transfer. This will appear on the bank statement of both the debtor and creditor.

    It must begin with an alphanumeric character, followed by any combination of letters, numbers, spaces or special characters `/ - ? : ( ) . , ' + _`.

    Constraints:
    - Cannot be solely a hyphen (-) or colon (:)
    - Cannot contain consecutive hyphens (--)
    - Cannot contain consecutive colons (::)
    """
    status_reason: NotRequired[Nullable[StatusReason2TypedDict]]
    r"""A human-readable reason explaining the current status of the transfer. Only populated when the transfer has
    reached a terminal status of `failed`, `rejected`, or `blocked`.

    This field is `null` for transfers that have not reached one of these statuses.
    """
    metadata: NotRequired[Nullable[MetadataTypedDict]]
    r"""Provide any data you like, for example a string or a JSON object. We will save the data alongside the entity. Whenever
    you fetch the entity with our API, we will also include the metadata. You can use up to approximately 1kB.
    """


class TransferResponse(BaseModel):
    resource: str
    r"""Indicates the response contains a transfer object. Will always contain the string `business-account-transfer`
    for this endpoint.
    """

    id: str
    r"""The identifier uniquely referring to this transfer. Mollie assigns this identifier at transfer creation time."""

    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""

    debtor: Debtor
    r"""The debtor (sender) of the transfer, including their name and account details."""

    creditor: TransferParty
    r"""A party involved in the transfer, representing either the debtor (sender) or creditor (recipient).
    Contains the party's name and account details.
    """

    amount: Amount
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""

    business_account_transaction_id: Annotated[
        str, pydantic.Field(alias="businessAccountTransactionId")
    ]
    r"""The identifier of the corresponding transaction in the business accounts transaction resource."""

    transfer_scheme: Annotated[
        TransferSchemeResponse, pydantic.Field(alias="transferScheme")
    ]
    r"""The scheme, as requested by the client."""

    credit_debit_indicator: Annotated[
        CreditDebitIndicator, pydantic.Field(alias="creditDebitIndicator")
    ]
    r"""Indicates whether the transfer is a credit or debit transaction from the perspective of the account holder."""

    status: TransferStatus
    r"""The status of the transfer."""

    status_history: Annotated[
        List[StatusHistoryEntryResponse], pydantic.Field(alias="statusHistory")
    ]
    r"""A chronological list of status transitions the transfer has gone through."""

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""

    description: OptionalNullable[str] = UNSET
    r"""A short description of the transfer. This will appear on the bank statement of both the debtor and creditor.

    It must begin with an alphanumeric character, followed by any combination of letters, numbers, spaces or special characters `/ - ? : ( ) . , ' + _`.

    Constraints:
    - Cannot be solely a hyphen (-) or colon (:)
    - Cannot contain consecutive hyphens (--)
    - Cannot contain consecutive colons (::)
    """

    status_reason: Annotated[
        OptionalNullable[StatusReason2], pydantic.Field(alias="statusReason")
    ] = UNSET
    r"""A human-readable reason explaining the current status of the transfer. Only populated when the transfer has
    reached a terminal status of `failed`, `rejected`, or `blocked`.

    This field is `null` for transfers that have not reached one of these statuses.
    """

    metadata: OptionalNullable[Metadata] = UNSET
    r"""Provide any data you like, for example a string or a JSON object. We will save the data alongside the entity. Whenever
    you fetch the entity with our API, we will also include the metadata. You can use up to approximately 1kB.
    """

    @field_serializer("mode")
    def serialize_mode(self, value):
        if isinstance(value, str):
            try:
                return models.Mode(value)
            except ValueError:
                return value
        return value

    @field_serializer("credit_debit_indicator")
    def serialize_credit_debit_indicator(self, value):
        if isinstance(value, str):
            try:
                return models.CreditDebitIndicator(value)
            except ValueError:
                return value
        return value

    @field_serializer("status")
    def serialize_status(self, value):
        if isinstance(value, str):
            try:
                return models.TransferStatus(value)
            except ValueError:
                return value
        return value

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["description", "statusReason", "metadata"])
        nullable_fields = set(["description", "statusReason", "metadata"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


try:
    Debtor.model_rebuild()
except NameError:
    pass
try:
    TransferResponse.model_rebuild()
except NameError:
    pass
