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

from __future__ import annotations
from .alertsettings import AlertSettings, AlertSettingsTypedDict
from .autotopup import AutoTopup, AutoTopupTypedDict
from .wallettype import WalletType
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreateWalletRequestTypedDict(TypedDict):
    currency: str
    alert_settings: NotRequired[AlertSettingsTypedDict]
    auto_topup: NotRequired[AutoTopupTypedDict]
    conversion_rate: NotRequired[str]
    r"""amount in the currency =  number of credits * conversion_rate
    ex if conversion_rate is 1, then 1 USD = 1 credit
    ex if conversion_rate is 2, then 1 USD = 0.5 credits
    ex if conversion_rate is 0.5, then 1 USD = 2 credits
    """
    customer_id: NotRequired[str]
    description: NotRequired[str]
    external_customer_id: NotRequired[str]
    r"""external_customer_id is the customer id in the external system"""
    initial_credits_expiry_date_utc: NotRequired[str]
    r"""initial_credits_expiry_date_utc is the expiry date in UTC timezone (optional to set nil means no expiry)
    ex 2025-01-01 00:00:00 UTC
    """
    initial_credits_to_load: NotRequired[str]
    r"""initial_credits_to_load is the number of credits to load to the wallet
    if not provided, the wallet will be created with 0 balance
    NOTE: this is not the amount in the currency, but the number of credits
    """
    initial_credits_to_load_expiry_date: NotRequired[int]
    r"""initial_credits_to_load_expiry_date YYYYMMDD format in UTC timezone (optional to set nil means no expiry)
    for ex 20250101 means the credits will expire on 2025-01-01 00:00:00 UTC
    hence they will be available for use until 2024-12-31 23:59:59 UTC
    """
    metadata: NotRequired[Dict[str, str]]
    price_unit: NotRequired[str]
    r"""price_unit is the code of the price unit to use for wallet creation
    If provided, the price unit will be used to set the currency and conversion rate of the wallet:
    - currency: set to price unit's base_currency
    - conversion_rate: set to price unit's conversion_rate
    """
    topup_conversion_rate: NotRequired[str]
    r"""topup_conversion_rate is the conversion rate for the topup to the currency
    ex if topup_conversion_rate is 1, then 1 USD = 1 credit
    ex if topup_conversion_rate is 2, then 1 USD = 0.5 credits
    ex if topup_conversion_rate is 0.5, then 1 USD = 2 credits
    """
    wallet_type: NotRequired[WalletType]


class DtoCreateWalletRequest(BaseModel):
    currency: str

    alert_settings: Optional[AlertSettings] = None

    auto_topup: Optional[AutoTopup] = None

    conversion_rate: Optional[str] = "1"
    r"""amount in the currency =  number of credits * conversion_rate
    ex if conversion_rate is 1, then 1 USD = 1 credit
    ex if conversion_rate is 2, then 1 USD = 0.5 credits
    ex if conversion_rate is 0.5, then 1 USD = 2 credits
    """

    customer_id: Optional[str] = None

    description: Optional[str] = None

    external_customer_id: Optional[str] = None
    r"""external_customer_id is the customer id in the external system"""

    initial_credits_expiry_date_utc: Optional[str] = None
    r"""initial_credits_expiry_date_utc is the expiry date in UTC timezone (optional to set nil means no expiry)
    ex 2025-01-01 00:00:00 UTC
    """

    initial_credits_to_load: Optional[str] = "0"
    r"""initial_credits_to_load is the number of credits to load to the wallet
    if not provided, the wallet will be created with 0 balance
    NOTE: this is not the amount in the currency, but the number of credits
    """

    initial_credits_to_load_expiry_date: Optional[int] = None
    r"""initial_credits_to_load_expiry_date YYYYMMDD format in UTC timezone (optional to set nil means no expiry)
    for ex 20250101 means the credits will expire on 2025-01-01 00:00:00 UTC
    hence they will be available for use until 2024-12-31 23:59:59 UTC
    """

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

    price_unit: Optional[str] = None
    r"""price_unit is the code of the price unit to use for wallet creation
    If provided, the price unit will be used to set the currency and conversion rate of the wallet:
    - currency: set to price unit's base_currency
    - conversion_rate: set to price unit's conversion_rate
    """

    topup_conversion_rate: Optional[str] = None
    r"""topup_conversion_rate is the conversion rate for the topup to the currency
    ex if topup_conversion_rate is 1, then 1 USD = 1 credit
    ex if topup_conversion_rate is 2, then 1 USD = 0.5 credits
    ex if topup_conversion_rate is 0.5, then 1 USD = 2 credits
    """

    wallet_type: Optional[WalletType] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "alert_settings",
                "auto_topup",
                "conversion_rate",
                "customer_id",
                "description",
                "external_customer_id",
                "initial_credits_expiry_date_utc",
                "initial_credits_to_load",
                "initial_credits_to_load_expiry_date",
                "metadata",
                "price_unit",
                "topup_conversion_rate",
                "wallet_type",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
