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

from __future__ import annotations
from .transfer_request import TransferRequest, TransferRequestTypedDict
from mollie.types import BaseModel, UNSET_SENTINEL
from mollie.utils import FieldMetadata, HeaderMetadata, RequestMetadata
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateTransferRequestTypedDict(TypedDict):
    x_client_signature: str
    r"""A cryptographic signature of the request payload, used to verify the authenticity of the transfer request."""
    x_client_signed_at: str
    r"""The timestamp (in ISO 8601 format) indicating when the client signed the request. Used in conjunction with
    `X-Client-Signature` for request verification.
    """
    idempotency_key: str
    r"""A unique value used to identify this request and prevent duplicate transfers. UUIDv4 is recommended to
    guarantee uniqueness across multiple processes or servers. If two requests are received with the same
    idempotency key, the second request will be discarded.

    View the [public documentation](https://docs.mollie.com/reference/api-idempotency#using-an-idempotency-key)
    to learn more.
    """
    idempotency_key1: NotRequired[str]
    r"""A unique key to ensure idempotent requests. This key should be a UUID v4 string."""
    transfer_request: NotRequired[TransferRequestTypedDict]


class CreateTransferRequest(BaseModel):
    x_client_signature: Annotated[
        str,
        pydantic.Field(alias="X-Client-Signature"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ]
    r"""A cryptographic signature of the request payload, used to verify the authenticity of the transfer request."""

    x_client_signed_at: Annotated[
        str,
        pydantic.Field(alias="X-Client-Signed-At"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ]
    r"""The timestamp (in ISO 8601 format) indicating when the client signed the request. Used in conjunction with
    `X-Client-Signature` for request verification.
    """

    idempotency_key: Annotated[
        str,
        pydantic.Field(alias="Idempotency-Key"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ]
    r"""A unique value used to identify this request and prevent duplicate transfers. UUIDv4 is recommended to
    guarantee uniqueness across multiple processes or servers. If two requests are received with the same
    idempotency key, the second request will be discarded.

    View the [public documentation](https://docs.mollie.com/reference/api-idempotency#using-an-idempotency-key)
    to learn more.
    """

    idempotency_key1: Annotated[
        Optional[str],
        pydantic.Field(alias="idempotency-key"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""A unique key to ensure idempotent requests. This key should be a UUID v4 string."""

    transfer_request: Annotated[
        Optional[TransferRequest],
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ] = None

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