"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from moovio_sdk.models.components import (
    card as components_card,
    linkcard as components_linkcard,
    linkcardwaitfor as components_linkcardwaitfor,
)
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
from moovio_sdk.utils import (
    FieldMetadata,
    HeaderMetadata,
    PathParamMetadata,
    RequestMetadata,
)
import pydantic
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class LinkCardRequestTypedDict(TypedDict):
    account_id: str
    link_card: components_linkcard.LinkCardTypedDict
    x_wait_for: NotRequired[components_linkcardwaitfor.LinkCardWaitFor]
    r"""Optional header to wait for certain events, such as the creation of a payment method, to occur before returning a response.

    When this header is set to `payment-method`, the response will include any payment methods that were created for the newly
    linked card in the `paymentMethods` field. Otherwise, the `paymentMethods` field will be omitted from the response.
    """


class LinkCardRequest(BaseModel):
    account_id: Annotated[
        str,
        pydantic.Field(alias="accountID"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]

    link_card: Annotated[
        components_linkcard.LinkCard,
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ]

    x_wait_for: Annotated[
        Optional[components_linkcardwaitfor.LinkCardWaitFor],
        pydantic.Field(alias="x-wait-for"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""Optional header to wait for certain events, such as the creation of a payment method, to occur before returning a response.

    When this header is set to `payment-method`, the response will include any payment methods that were created for the newly
    linked card in the `paymentMethods` field. Otherwise, the `paymentMethods` field will be omitted from the response.
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["x-wait-for"])
        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 LinkCardResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: components_card.CardTypedDict


class LinkCardResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: components_card.Card
