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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .balance_transfer_category_response import BalanceTransferCategoryResponse
from .balance_transfer_status import BalanceTransferStatus
from .balance_transfer_status_reason_response import BalanceTransferStatusReasonResponse
from .entity_balance_transfer_party_response import (
    EntityBalanceTransferPartyResponse,
    EntityBalanceTransferPartyResponseTypedDict,
)
from .mode import Mode
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 Any, Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class EntityBalanceTransferResponseStatusReasonTypedDict(TypedDict):
    r"""The reason for the current status of the transfer, if applicable."""

    code: BalanceTransferStatusReasonResponse
    r"""A machine-readable code that indicates the reason for the transfer's status."""
    message: str
    r"""A description of the status reason, localized according to the transfer."""


class EntityBalanceTransferResponseStatusReason(BaseModel):
    r"""The reason for the current status of the transfer, if applicable."""

    code: BalanceTransferStatusReasonResponse
    r"""A machine-readable code that indicates the reason for the transfer's status."""

    message: str
    r"""A description of the status reason, localized according to the transfer."""

    @field_serializer("code")
    def serialize_code(self, value):
        if isinstance(value, str):
            try:
                return models.BalanceTransferStatusReasonResponse(value)
            except ValueError:
                return value
        return value


class EntityBalanceTransferResponseTypedDict(TypedDict):
    resource: str
    r"""Indicates the response contains a balance transfer object. Will always contain the string `connect-balance-transfer` for this endpoint."""
    id: str
    r"""The identifier uniquely referring to this balance transfer. Mollie assigns this identifier at balance transfer creation time. Mollie
    will always refer to the balance transfer by this ID. Example: `cbtr_j8NvRAM2WNZtsykpLEX8J`.
    """
    amount: AmountTypedDict
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""
    source: EntityBalanceTransferPartyResponseTypedDict
    r"""A party involved in the balance transfer, either the sender or the receiver."""
    destination: EntityBalanceTransferPartyResponseTypedDict
    r"""A party involved in the balance transfer, either the sender or the receiver."""
    description: str
    r"""The transfer description for initiating party."""
    status: BalanceTransferStatus
    r"""The status of the transfer."""
    status_reason: EntityBalanceTransferResponseStatusReasonTypedDict
    r"""The reason for the current status of the transfer, if applicable."""
    created_at: str
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""
    mode: Mode
    r"""Whether this entity was created in live mode or in test mode."""
    category: NotRequired[BalanceTransferCategoryResponse]
    r"""The type of the transfer. Different fees may apply to different types of transfers."""
    metadata: NotRequired[Dict[str, Any]]
    r"""A JSON object that you can attach to a balance transfer.
    This can be useful for storing additional information about the transfer in a structured format. Maximum size is approximately 1KB.
    """
    executed_at: NotRequired[Nullable[str]]
    r"""The date and time when the transfer was completed, in ISO 8601 format. This parameter is omitted if the transfer is
    not executed (yet).
    """


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

    id: str
    r"""The identifier uniquely referring to this balance transfer. Mollie assigns this identifier at balance transfer creation time. Mollie
    will always refer to the balance transfer by this ID. Example: `cbtr_j8NvRAM2WNZtsykpLEX8J`.
    """

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

    source: EntityBalanceTransferPartyResponse
    r"""A party involved in the balance transfer, either the sender or the receiver."""

    destination: EntityBalanceTransferPartyResponse
    r"""A party involved in the balance transfer, either the sender or the receiver."""

    description: str
    r"""The transfer description for initiating party."""

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

    status_reason: Annotated[
        EntityBalanceTransferResponseStatusReason, pydantic.Field(alias="statusReason")
    ]
    r"""The reason for the current status of the transfer, if applicable."""

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

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

    category: Optional[BalanceTransferCategoryResponse] = None
    r"""The type of the transfer. Different fees may apply to different types of transfers."""

    metadata: Optional[Dict[str, Any]] = None
    r"""A JSON object that you can attach to a balance transfer.
    This can be useful for storing additional information about the transfer in a structured format. Maximum size is approximately 1KB.
    """

    executed_at: Annotated[
        OptionalNullable[str], pydantic.Field(alias="executedAt")
    ] = UNSET
    r"""The date and time when the transfer was completed, in ISO 8601 format. This parameter is omitted if the transfer is
    not executed (yet).
    """

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

    @field_serializer("category")
    def serialize_category(self, value):
        if isinstance(value, str):
            try:
                return models.BalanceTransferCategoryResponse(value)
            except ValueError:
                return value
        return value

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

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