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

from __future__ import annotations
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 DtoCreatePriceUnitRequestTypedDict(TypedDict):
    base_currency: str
    r"""base_currency  is the currency that the price unit is based on"""
    code: str
    conversion_rate: str
    r"""ConversionRate defines the exchange rate from this price unit to the base currency.
    This rate is used to convert amounts in the custom price unit to the base currency for storage and billing.

    Conversion formula:
    price_unit_amount * conversion_rate = base_currency_amount

    Example:
    If conversion_rate = \"0.01\" and base_currency = \"usd\":
    100 price_unit tokens * 0.01 = 1.00 USD

    Note: Rounding precision is determined by the base currency (e.g., USD uses 2 decimal places, JPY uses 0).
    """
    name: str
    symbol: str
    metadata: NotRequired[Dict[str, str]]


class DtoCreatePriceUnitRequest(BaseModel):
    base_currency: str
    r"""base_currency  is the currency that the price unit is based on"""

    code: str

    conversion_rate: str
    r"""ConversionRate defines the exchange rate from this price unit to the base currency.
    This rate is used to convert amounts in the custom price unit to the base currency for storage and billing.

    Conversion formula:
    price_unit_amount * conversion_rate = base_currency_amount

    Example:
    If conversion_rate = \"0.01\" and base_currency = \"usd\":
    100 price_unit tokens * 0.01 = 1.00 USD

    Note: Rounding precision is determined by the base currency (e.g., USD uses 2 decimal places, JPY uses 0).
    """

    name: str

    symbol: str

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

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