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

from __future__ import annotations
from .transactionreason import TransactionReason
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoTopUpWalletRequestTypedDict(TypedDict):
    transaction_reason: TransactionReason
    amount: NotRequired[str]
    r"""amount is the amount in the currency of the wallet to be added
    NOTE: this is not the number of credits to add, but the amount in the currency
    amount = credits_to_add * conversion_rate
    if both amount and credits_to_add are provided, amount will be ignored
    ex if the wallet has a conversion_rate of 2 then adding an amount of
    10 USD in the wallet wil add 5 credits in the wallet
    """
    credits_to_add: NotRequired[str]
    r"""credits_to_add is the number of credits to add to the wallet"""
    description: NotRequired[str]
    r"""description to add any specific details about the transaction"""
    expiry_date_utc: NotRequired[str]
    r"""expiry_date_utc is the expiry date in UTC timezone
    ex 2025-01-01 00:00:00 UTC
    """
    idempotency_key: NotRequired[str]
    r"""idempotency_key is a unique key for the transaction"""
    metadata: NotRequired[Dict[str, str]]
    priority: NotRequired[int]
    r"""priority is the priority of the transaction
    lower number means higher priority
    default is nil which means no priority at all
    """


class DtoTopUpWalletRequest(BaseModel):
    transaction_reason: TransactionReason

    amount: Optional[str] = None
    r"""amount is the amount in the currency of the wallet to be added
    NOTE: this is not the number of credits to add, but the amount in the currency
    amount = credits_to_add * conversion_rate
    if both amount and credits_to_add are provided, amount will be ignored
    ex if the wallet has a conversion_rate of 2 then adding an amount of
    10 USD in the wallet wil add 5 credits in the wallet
    """

    credits_to_add: Optional[str] = None
    r"""credits_to_add is the number of credits to add to the wallet"""

    description: Optional[str] = None
    r"""description to add any specific details about the transaction"""

    expiry_date_utc: Optional[str] = None
    r"""expiry_date_utc is the expiry date in UTC timezone
    ex 2025-01-01 00:00:00 UTC
    """

    idempotency_key: Optional[str] = None
    r"""idempotency_key is a unique key for the transaction"""

    metadata: Optional[Dict[str, str]] = None

    priority: Optional[int] = None
    r"""priority is the priority of the transaction
    lower number means higher priority
    default is nil which means no priority at all
    """

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "credits_to_add",
                "description",
                "expiry_date_utc",
                "idempotency_key",
                "metadata",
                "priority",
            ]
        )
        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
