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

from __future__ import annotations
from moovio_sdk.models.components import (
    cardacquiringrefund as components_cardacquiringrefund,
    createrefund as components_createrefund,
    createrefundresponse as components_createrefundresponse,
    transferwaitfor as components_transferwaitfor,
)
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, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class InitiateRefundRequestTypedDict(TypedDict):
    x_idempotency_key: str
    r"""Prevents duplicate refunds from being created."""
    account_id: str
    r"""The merchant's Moov account ID."""
    transfer_id: str
    r"""Identifier for the transfer."""
    x_wait_for: NotRequired[components_transferwaitfor.TransferWaitFor]
    r"""Optional header that indicates whether to return a synchronous response that includes full transfer and rail-specific details or an
    asynchronous response indicating the transfer was created (this is the default response if the header is omitted). A timeout will occur after 15 seconds.
    """
    create_refund: NotRequired[components_createrefund.CreateRefundTypedDict]


class InitiateRefundRequest(BaseModel):
    x_idempotency_key: Annotated[
        str,
        pydantic.Field(alias="x-idempotency-key"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ]
    r"""Prevents duplicate refunds from being created."""

    account_id: Annotated[
        str,
        pydantic.Field(alias="accountID"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]
    r"""The merchant's Moov account ID."""

    transfer_id: Annotated[
        str,
        pydantic.Field(alias="transferID"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]
    r"""Identifier for the transfer."""

    x_wait_for: Annotated[
        Optional[components_transferwaitfor.TransferWaitFor],
        pydantic.Field(alias="x-wait-for"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""Optional header that indicates whether to return a synchronous response that includes full transfer and rail-specific details or an
    asynchronous response indicating the transfer was created (this is the default response if the header is omitted). A timeout will occur after 15 seconds.
    """

    create_refund: Annotated[
        Optional[components_createrefund.CreateRefund],
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ] = None

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


InitiateRefundResponseResultTypedDict = TypeAliasType(
    "InitiateRefundResponseResultTypedDict",
    Union[
        components_cardacquiringrefund.CardAcquiringRefundTypedDict,
        components_createrefundresponse.CreateRefundResponseTypedDict,
    ],
)


InitiateRefundResponseResult = TypeAliasType(
    "InitiateRefundResponseResult",
    Union[
        components_cardacquiringrefund.CardAcquiringRefund,
        components_createrefundresponse.CreateRefundResponse,
    ],
)


class InitiateRefundResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: InitiateRefundResponseResultTypedDict


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

    result: InitiateRefundResponseResult
