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

from __future__ import annotations
from .adyencardautorescuescenariosenum import AdyenCardAutoRescueScenariosEnum
from .adyensplitsoptions import AdyenSplitsOptions, AdyenSplitsOptionsTypedDict
from gr4vy.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Dict
from typing_extensions import Annotated, NotRequired, TypedDict


class AdyenCardOptionsTypedDict(TypedDict):
    auto_rescue: NotRequired[Nullable[bool]]
    r"""Set to `true` to enable Auto Rescue for a transaction. Use the `maxDaysToRescue` to specify a rescue window."""
    max_days_to_rescue: NotRequired[Nullable[int]]
    r"""The rescue window for a transaction, in days, when `autoRescue` is set to `true`. You can specify a value between 1 and 48. For cards, the default is one calendar month. For SEPA, the default is 42 days."""
    additional_data: NotRequired[Nullable[Dict[str, str]]]
    r"""Passes additional data to the Adyen API when creating a transaction."""
    auto_rescue_scenario: NotRequired[Nullable[AdyenCardAutoRescueScenariosEnum]]
    r"""The rescue scenario to simulate for a transaction, when `autoRescue` is set to `true`."""
    window_origin: NotRequired[Nullable[str]]
    r"""The origin of the window where the payment is initiated, used for 3D Secure authentication."""
    splits: NotRequired[Nullable[AdyenSplitsOptionsTypedDict]]
    r"""Passes information of splitting payment amounts to the Adyen API."""


class AdyenCardOptions(BaseModel):
    auto_rescue: Annotated[
        OptionalNullable[bool], pydantic.Field(alias="autoRescue")
    ] = UNSET
    r"""Set to `true` to enable Auto Rescue for a transaction. Use the `maxDaysToRescue` to specify a rescue window."""

    max_days_to_rescue: Annotated[
        OptionalNullable[int], pydantic.Field(alias="maxDaysToRescue")
    ] = UNSET
    r"""The rescue window for a transaction, in days, when `autoRescue` is set to `true`. You can specify a value between 1 and 48. For cards, the default is one calendar month. For SEPA, the default is 42 days."""

    additional_data: Annotated[
        OptionalNullable[Dict[str, str]], pydantic.Field(alias="additionalData")
    ] = UNSET
    r"""Passes additional data to the Adyen API when creating a transaction."""

    auto_rescue_scenario: Annotated[
        OptionalNullable[AdyenCardAutoRescueScenariosEnum],
        pydantic.Field(alias="autoRescueScenario"),
    ] = UNSET
    r"""The rescue scenario to simulate for a transaction, when `autoRescue` is set to `true`."""

    window_origin: OptionalNullable[str] = UNSET
    r"""The origin of the window where the payment is initiated, used for 3D Secure authentication."""

    splits: OptionalNullable[AdyenSplitsOptions] = UNSET
    r"""Passes information of splitting payment amounts to the Adyen API."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "autoRescue",
                "maxDaysToRescue",
                "additionalData",
                "autoRescueScenario",
                "window_origin",
                "splits",
            ]
        )
        nullable_fields = set(
            [
                "autoRescue",
                "maxDaysToRescue",
                "additionalData",
                "autoRescueScenario",
                "window_origin",
                "splits",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
