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

from __future__ import annotations
from .transaction import Transaction, TransactionTypedDict
from .transactionvoid import TransactionVoid, TransactionVoidTypedDict
from gr4vy.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from gr4vy.utils import FieldMetadata, HeaderMetadata, PathParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class VoidTransactionGlobalsTypedDict(TypedDict):
    merchant_account_id: NotRequired[str]
    r"""The ID of the merchant account to use for this request."""


class VoidTransactionGlobals(BaseModel):
    merchant_account_id: Annotated[
        Optional[str],
        pydantic.Field(alias="x-gr4vy-merchant-account-id"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The ID of the merchant account to use for this request."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["merchant_account_id"])
        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 VoidTransactionRequestTypedDict(TypedDict):
    transaction_id: str
    r"""The ID of the transaction"""
    prefer: NotRequired[Nullable[List[str]]]
    r"""The preferred resource type in the response."""
    merchant_account_id: NotRequired[str]
    r"""The ID of the merchant account to use for this request."""
    idempotency_key: NotRequired[Nullable[str]]
    r"""A unique key that identifies this request. Providing this header will make this an idempotent request. We recommend using V4 UUIDs, or another random string with enough entropy to avoid collisions."""


class VoidTransactionRequest(BaseModel):
    transaction_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The ID of the transaction"""

    prefer: Annotated[
        OptionalNullable[List[str]],
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = UNSET
    r"""The preferred resource type in the response."""

    merchant_account_id: Annotated[
        Optional[str],
        pydantic.Field(alias="x-gr4vy-merchant-account-id"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The ID of the merchant account to use for this request."""

    idempotency_key: Annotated[
        OptionalNullable[str],
        pydantic.Field(alias="idempotency-key"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = UNSET
    r"""A unique key that identifies this request. Providing this header will make this an idempotent request. We recommend using V4 UUIDs, or another random string with enough entropy to avoid collisions."""

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


Response200VoidTransactionTypedDict = TypeAliasType(
    "Response200VoidTransactionTypedDict",
    Union[TransactionVoidTypedDict, TransactionTypedDict],
)
r"""Successful Response"""


Response200VoidTransaction = TypeAliasType(
    "Response200VoidTransaction", Union[TransactionVoid, Transaction]
)
r"""Successful Response"""
