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

from __future__ import annotations
from .amount import Amount, AmountTypedDict
from .unmatched_credit_transfer_status import UnmatchedCreditTransferStatus
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, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListEntityUnmatchedCreditTransferSourceTypedDict(TypedDict):
    r"""Details about the sender of the credit transfer."""

    format_: str
    r"""The format of the source account. Currently always `iban`."""
    account_holder_name: str
    r"""The name of the account holder who sent the unmatched credit transfer."""
    iban: str
    r"""The IBAN of the sender's bank account."""
    bic: str
    r"""The BIC of the sender's bank."""


class ListEntityUnmatchedCreditTransferSource(BaseModel):
    r"""Details about the sender of the credit transfer."""

    format_: Annotated[str, pydantic.Field(alias="format")]
    r"""The format of the source account. Currently always `iban`."""

    account_holder_name: Annotated[str, pydantic.Field(alias="accountHolderName")]
    r"""The name of the account holder who sent the unmatched credit transfer."""

    iban: str
    r"""The IBAN of the sender's bank account."""

    bic: str
    r"""The BIC of the sender's bank."""


class ListEntityUnmatchedCreditTransferReferencesTypedDict(TypedDict):
    r"""Structured references provided with the unmatched credit transfer."""

    creditor_reference: NotRequired[Nullable[str]]
    r"""The creditor reference."""
    end_to_end_id: NotRequired[str]
    r"""The end-to-end identifier."""


class ListEntityUnmatchedCreditTransferReferences(BaseModel):
    r"""Structured references provided with the unmatched credit transfer."""

    creditor_reference: Annotated[
        OptionalNullable[str], pydantic.Field(alias="creditorReference")
    ] = UNSET
    r"""The creditor reference."""

    end_to_end_id: Annotated[Optional[str], pydantic.Field(alias="endToEndId")] = None
    r"""The end-to-end identifier."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["creditorReference", "endToEndId"])
        nullable_fields = set(["creditorReference"])
        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


class ListEntityUnmatchedCreditTransferRemittanceInformationTypedDict(TypedDict):
    r"""Remittance information provided with the unmatched credit transfer."""

    unstructured: NotRequired[str]
    r"""Unstructured remittance information, such as a free-text payment description."""
    references: NotRequired[ListEntityUnmatchedCreditTransferReferencesTypedDict]
    r"""Structured references provided with the unmatched credit transfer."""


class ListEntityUnmatchedCreditTransferRemittanceInformation(BaseModel):
    r"""Remittance information provided with the unmatched credit transfer."""

    unstructured: Optional[str] = None
    r"""Unstructured remittance information, such as a free-text payment description."""

    references: Optional[ListEntityUnmatchedCreditTransferReferences] = None
    r"""Structured references provided with the unmatched credit transfer."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["unstructured", "references"])
        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))

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

        return m


class ListEntityUnmatchedCreditTransferSelfTypedDict(TypedDict):
    r"""The URL to this unmatched credit transfer."""

    href: NotRequired[str]
    type: NotRequired[str]


class ListEntityUnmatchedCreditTransferSelf(BaseModel):
    r"""The URL to this unmatched credit transfer."""

    href: Optional[str] = None

    type: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["href", "type"])
        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))

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

        return m


class ListEntityUnmatchedCreditTransferLinksTypedDict(TypedDict):
    r"""Links to related resources."""

    self_: NotRequired[ListEntityUnmatchedCreditTransferSelfTypedDict]
    r"""The URL to this unmatched credit transfer."""


class ListEntityUnmatchedCreditTransferLinks(BaseModel):
    r"""Links to related resources."""

    self_: Annotated[
        Optional[ListEntityUnmatchedCreditTransferSelf], pydantic.Field(alias="self")
    ] = None
    r"""The URL to this unmatched credit transfer."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["self"])
        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))

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

        return m


class ListEntityUnmatchedCreditTransferTypedDict(TypedDict):
    resource: str
    r"""Indicates the response contains an unmatched credit transfer object. Will always contain the string
    `unmatched-credit-transfer` for this endpoint.
    """
    id: str
    r"""The identifier uniquely referring to this unmatched credit transfer."""
    profile_id: str
    amount: AmountTypedDict
    r"""In v2 endpoints, monetary amounts are represented as objects with a `currency` and `value` field."""
    source: ListEntityUnmatchedCreditTransferSourceTypedDict
    r"""Details about the sender of the credit transfer."""
    remittance_information: (
        ListEntityUnmatchedCreditTransferRemittanceInformationTypedDict
    )
    r"""Remittance information provided with the unmatched credit transfer."""
    status: UnmatchedCreditTransferStatus
    created_at: str
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""
    expires_at: str
    r"""The date and time at which the unmatched credit transfer expires, in
    [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    """
    links: ListEntityUnmatchedCreditTransferLinksTypedDict
    r"""Links to related resources."""
    payment_ids: NotRequired[List[str]]
    r"""The IDs of the payments this credit transfer was matched to. Only present when the status is `matched`."""


class ListEntityUnmatchedCreditTransfer(BaseModel):
    resource: str
    r"""Indicates the response contains an unmatched credit transfer object. Will always contain the string
    `unmatched-credit-transfer` for this endpoint.
    """

    id: str
    r"""The identifier uniquely referring to this unmatched credit transfer."""

    profile_id: Annotated[str, pydantic.Field(alias="profileId")]

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

    source: ListEntityUnmatchedCreditTransferSource
    r"""Details about the sender of the credit transfer."""

    remittance_information: Annotated[
        ListEntityUnmatchedCreditTransferRemittanceInformation,
        pydantic.Field(alias="remittanceInformation"),
    ]
    r"""Remittance information provided with the unmatched credit transfer."""

    status: UnmatchedCreditTransferStatus

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

    expires_at: Annotated[str, pydantic.Field(alias="expiresAt")]
    r"""The date and time at which the unmatched credit transfer expires, in
    [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
    """

    links: Annotated[
        ListEntityUnmatchedCreditTransferLinks, pydantic.Field(alias="_links")
    ]
    r"""Links to related resources."""

    payment_ids: Annotated[Optional[List[str]], pydantic.Field(alias="paymentIds")] = (
        None
    )
    r"""The IDs of the payments this credit transfer was matched to. Only present when the status is `matched`."""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["paymentIds"])
        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))

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

        return m


try:
    ListEntityUnmatchedCreditTransferSource.model_rebuild()
except NameError:
    pass
try:
    ListEntityUnmatchedCreditTransferReferences.model_rebuild()
except NameError:
    pass
try:
    ListEntityUnmatchedCreditTransferLinks.model_rebuild()
except NameError:
    pass
try:
    ListEntityUnmatchedCreditTransfer.model_rebuild()
except NameError:
    pass
