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

from __future__ import annotations
from .status_reason_2 import StatusReason2, StatusReason2TypedDict
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_extensions import Annotated, NotRequired, TypedDict


class StatusHistoryEntryResponseTypedDict(TypedDict):
    r"""Represents an entry in the transfer's status history, recording a past status transition."""

    status: TransferStatus
    r"""The status of the transfer."""
    created_at: str
    r"""The entity's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."""
    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.
    """


class StatusHistoryEntryResponse(BaseModel):
    r"""Represents an entry in the transfer's status history, recording a past status transition."""

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

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

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

    @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(["statusReason"])
        nullable_fields = set(["statusReason"])
        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:
    StatusHistoryEntryResponse.model_rebuild()
except NameError:
    pass
