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

from __future__ import annotations
from .dlocalpixsubscriptionamountoptions import (
    DlocalPIXSubscriptionAmountOptions,
    DlocalPIXSubscriptionAmountOptionsTypedDict,
)
from gr4vy.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from pydantic import model_serializer
from typing import Literal, Union
from typing_extensions import NotRequired, TypedDict


Frequency = Union[
    Literal[
        "WEEKLY",
        "MONTHLY",
        "QUARTERLY",
        "SEMI_ANNUAL",
        "ANNUAL",
    ],
    UnrecognizedStr,
]
r"""Indicates the frequency unit for the subscription. Allowed values are: `WEEKLY`, `MONTHLY`, `QUARTERLY`, `SEMI_ANNUAL`, `ANNUAL`."""


class DlocalPIXSubscriptionOptionsTypedDict(TypedDict):
    frequency: Frequency
    r"""Indicates the frequency unit for the subscription. Allowed values are: `WEEKLY`, `MONTHLY`, `QUARTERLY`, `SEMI_ANNUAL`, `ANNUAL`."""
    amount: NotRequired[Nullable[DlocalPIXSubscriptionAmountOptionsTypedDict]]
    r"""Passes `subscription.amount` to the dLocal API for those connectors that need it."""
    start_date: NotRequired[Nullable[str]]
    r"""Defines subscription start date. Must be provided in ISO 8601 format `(YYYY-MM-DD`). If not specified, The default is the current date."""
    end_date: NotRequired[Nullable[str]]
    r"""Defines subscription expiration date. Must be provided in ISO 8601 format `(YYYY-MM-DD`). If not provided, the subscription will not expire."""


class DlocalPIXSubscriptionOptions(BaseModel):
    frequency: Frequency
    r"""Indicates the frequency unit for the subscription. Allowed values are: `WEEKLY`, `MONTHLY`, `QUARTERLY`, `SEMI_ANNUAL`, `ANNUAL`."""

    amount: OptionalNullable[DlocalPIXSubscriptionAmountOptions] = UNSET
    r"""Passes `subscription.amount` to the dLocal API for those connectors that need it."""

    start_date: OptionalNullable[str] = UNSET
    r"""Defines subscription start date. Must be provided in ISO 8601 format `(YYYY-MM-DD`). If not specified, The default is the current date."""

    end_date: OptionalNullable[str] = UNSET
    r"""Defines subscription expiration date. Must be provided in ISO 8601 format `(YYYY-MM-DD`). If not provided, the subscription will not expire."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["amount", "start_date", "end_date"])
        nullable_fields = set(["amount", "start_date", "end_date"])
        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
