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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .metadata import Metadata, MetadataTypedDict
from .transfer_party import TransferParty, TransferPartyTypedDict
from .transfer_scheme import TransferScheme, TransferSchemeTypedDict
from mollie.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing_extensions import Annotated, NotRequired, TypedDict


class TransferRequestTypedDict(TypedDict):
    debtor_iban: str
    r"""The IBAN of the debtor's (sender) Mollie account from which to initiate the transfer."""
    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."""
    transfer_scheme: TransferSchemeTypedDict
    r"""The scheme, as requested by the client."""
    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 (::)
    """
    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.
    """
    testmode: NotRequired[Nullable[bool]]
    r"""Whether to create the entity in test mode or live mode.

    Most API credentials are specifically created for either live mode or test mode, in which case this parameter must
    not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting
    `testmode` to `true`.
    """


class TransferRequest(BaseModel):
    debtor_iban: Annotated[str, pydantic.Field(alias="debtorIban")]
    r"""The IBAN of the debtor's (sender) Mollie account from which to initiate the transfer."""

    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."""

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

    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 (::)
    """

    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.
    """

    testmode: OptionalNullable[bool] = UNSET
    r"""Whether to create the entity in test mode or live mode.

    Most API credentials are specifically created for either live mode or test mode, in which case this parameter must
    not be sent. For organization-level credentials such as OAuth access tokens, you can enable test mode by setting
    `testmode` to `true`.
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["description", "metadata", "testmode"])
        nullable_fields = set(["description", "metadata", "testmode"])
        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:
    TransferRequest.model_rebuild()
except NameError:
    pass
