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

from __future__ import annotations
from .alertsettings import AlertSettings, AlertSettingsTypedDict
from .alertstate import AlertState
from .autotopup import AutoTopup, AutoTopupTypedDict
from .creditbreakdown import CreditBreakdown, CreditBreakdownTypedDict
from .status import Status
from .walletconfig import WalletConfig, WalletConfigTypedDict
from .walletstatus import WalletStatus
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 DtoWalletBalanceResponseTypedDict(TypedDict):
    alert_settings: NotRequired[AlertSettingsTypedDict]
    alert_state: NotRequired[AlertState]
    auto_topup: NotRequired[AutoTopupTypedDict]
    balance: NotRequired[str]
    balance_updated_at: NotRequired[str]
    config: NotRequired[WalletConfigTypedDict]
    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
    """
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    credit_balance: NotRequired[str]
    credits_available_breakdown: NotRequired[CreditBreakdownTypedDict]
    currency: NotRequired[str]
    current_period_usage: NotRequired[str]
    customer_id: NotRequired[str]
    description: NotRequired[str]
    environment_id: NotRequired[str]
    id: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    name: NotRequired[str]
    real_time_balance: NotRequired[str]
    real_time_credit_balance: NotRequired[str]
    status: NotRequired[Status]
    tenant_id: NotRequired[str]
    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
    """
    unpaid_invoices_amount: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]
    wallet_status: NotRequired[WalletStatus]
    wallet_type: NotRequired[WalletType]


class DtoWalletBalanceResponse(BaseModel):
    alert_settings: Optional[AlertSettings] = None

    alert_state: Optional[AlertState] = None

    auto_topup: Optional[AutoTopup] = None

    balance: Optional[str] = None

    balance_updated_at: Optional[str] = None

    config: Optional[WalletConfig] = None

    conversion_rate: Optional[str] = None
    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
    """

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    credit_balance: Optional[str] = None

    credits_available_breakdown: Optional[CreditBreakdown] = None

    currency: Optional[str] = None

    current_period_usage: Optional[str] = None

    customer_id: Optional[str] = None

    description: Optional[str] = None

    environment_id: Optional[str] = None

    id: Optional[str] = None

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

    name: Optional[str] = None

    real_time_balance: Optional[str] = None

    real_time_credit_balance: Optional[str] = None

    status: Optional[Status] = None

    tenant_id: Optional[str] = None

    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
    """

    unpaid_invoices_amount: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    wallet_status: Optional[WalletStatus] = None

    wallet_type: Optional[WalletType] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "alert_settings",
                "alert_state",
                "auto_topup",
                "balance",
                "balance_updated_at",
                "config",
                "conversion_rate",
                "created_at",
                "created_by",
                "credit_balance",
                "credits_available_breakdown",
                "currency",
                "current_period_usage",
                "customer_id",
                "description",
                "environment_id",
                "id",
                "metadata",
                "name",
                "real_time_balance",
                "real_time_credit_balance",
                "status",
                "tenant_id",
                "topup_conversion_rate",
                "unpaid_invoices_amount",
                "updated_at",
                "updated_by",
                "wallet_status",
                "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
