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

from __future__ import annotations
from .billingcadence import BillingCadence
from .billingmodel import BillingModel
from .billingperiod import BillingPeriod
from .billingtier import BillingTier
from .invoicecadence import InvoiceCadence
from .price_jsonbtransformquantity import (
    PriceJSONBTransformQuantity,
    PriceJSONBTransformQuantityTypedDict,
)
from .price_pricetier import PricePriceTier, PricePriceTierTypedDict
from .priceentitytype import PriceEntityType
from .pricetype import PriceType
from .priceunittype import PriceUnitType
from .status import Status
from flexprice_py.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class PricePriceTypedDict(TypedDict):
    amount: NotRequired[str]
    r"""Amount stored in main currency units (e.g., dollars, not cents)
    For USD: 12.50 means $12.50
    """
    billing_cadence: NotRequired[BillingCadence]
    billing_model: NotRequired[BillingModel]
    billing_period: NotRequired[BillingPeriod]
    billing_period_count: NotRequired[int]
    r"""BillingPeriodCount is the count of the billing period ex 1, 3, 6, 12"""
    conversion_rate: NotRequired[str]
    r"""ConversionRate is the conversion rate of the price unit to the fiat currency"""
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    currency: NotRequired[str]
    r"""Currency 3 digit ISO currency code in lowercase ex usd, eur, gbp"""
    description: NotRequired[str]
    r"""Description of the price"""
    display_amount: NotRequired[str]
    r"""DisplayAmount is the formatted amount with currency symbol
    For USD: $12.50
    """
    display_name: NotRequired[str]
    r"""DisplayName is the name of the price"""
    display_price_unit_amount: NotRequired[str]
    r"""DisplayPriceUnitAmount is the formatted amount of the price unit"""
    end_date: NotRequired[str]
    r"""EndDate is the end date of the price"""
    entity_id: NotRequired[str]
    r"""EntityID holds the value of the \"entity_id\" field."""
    entity_type: NotRequired[PriceEntityType]
    environment_id: NotRequired[str]
    r"""EnvironmentID is the environment identifier for the price"""
    group_id: NotRequired[str]
    r"""GroupID references the group this price belongs to"""
    id: NotRequired[str]
    r"""ID uuid identifier for the price"""
    invoice_cadence: NotRequired[InvoiceCadence]
    lookup_key: NotRequired[str]
    r"""LookupKey used for looking up the price in the database"""
    metadata: NotRequired[Dict[str, str]]
    meter_id: NotRequired[str]
    r"""MeterID is the id of the meter for usage based pricing"""
    min_quantity: NotRequired[Nullable[str]]
    r"""MinQuantity is the minimum quantity of the price"""
    parent_price_id: NotRequired[str]
    r"""ParentPriceID references the root price (always set for price lineage tracking)"""
    price_unit: NotRequired[str]
    r"""PriceUnit is the code of the price unit (e.g., 'btc', 'eth')"""
    price_unit_amount: NotRequired[str]
    r"""PriceUnitAmount is the amount of the price unit"""
    price_unit_id: NotRequired[str]
    r"""PriceUnitID is the id of the price unit (for CUSTOM type)"""
    price_unit_tiers: NotRequired[List[PricePriceTierTypedDict]]
    r"""PriceUnitTiers are the tiers for the price unit when BillingModel is TIERED"""
    price_unit_type: NotRequired[PriceUnitType]
    start_date: NotRequired[str]
    r"""StartDate is the start date of the price"""
    status: NotRequired[Status]
    tenant_id: NotRequired[str]
    tier_mode: NotRequired[BillingTier]
    tiers: NotRequired[List[PricePriceTierTypedDict]]
    transform_quantity: NotRequired[PriceJSONBTransformQuantityTypedDict]
    trial_period: NotRequired[int]
    r"""TrialPeriod is the number of days for the trial period
    Note: This is only applicable for recurring prices (BILLING_CADENCE_RECURRING)
    """
    type: NotRequired[PriceType]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class PricePrice(BaseModel):
    amount: Optional[str] = None
    r"""Amount stored in main currency units (e.g., dollars, not cents)
    For USD: 12.50 means $12.50
    """

    billing_cadence: Optional[BillingCadence] = None

    billing_model: Optional[BillingModel] = None

    billing_period: Optional[BillingPeriod] = None

    billing_period_count: Optional[int] = None
    r"""BillingPeriodCount is the count of the billing period ex 1, 3, 6, 12"""

    conversion_rate: Optional[str] = None
    r"""ConversionRate is the conversion rate of the price unit to the fiat currency"""

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    currency: Optional[str] = None
    r"""Currency 3 digit ISO currency code in lowercase ex usd, eur, gbp"""

    description: Optional[str] = None
    r"""Description of the price"""

    display_amount: Optional[str] = None
    r"""DisplayAmount is the formatted amount with currency symbol
    For USD: $12.50
    """

    display_name: Optional[str] = None
    r"""DisplayName is the name of the price"""

    display_price_unit_amount: Optional[str] = None
    r"""DisplayPriceUnitAmount is the formatted amount of the price unit"""

    end_date: Optional[str] = None
    r"""EndDate is the end date of the price"""

    entity_id: Optional[str] = None
    r"""EntityID holds the value of the \"entity_id\" field."""

    entity_type: Optional[PriceEntityType] = None

    environment_id: Optional[str] = None
    r"""EnvironmentID is the environment identifier for the price"""

    group_id: Optional[str] = None
    r"""GroupID references the group this price belongs to"""

    id: Optional[str] = None
    r"""ID uuid identifier for the price"""

    invoice_cadence: Optional[InvoiceCadence] = None

    lookup_key: Optional[str] = None
    r"""LookupKey used for looking up the price in the database"""

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

    meter_id: Optional[str] = None
    r"""MeterID is the id of the meter for usage based pricing"""

    min_quantity: OptionalNullable[str] = UNSET
    r"""MinQuantity is the minimum quantity of the price"""

    parent_price_id: Optional[str] = None
    r"""ParentPriceID references the root price (always set for price lineage tracking)"""

    price_unit: Optional[str] = None
    r"""PriceUnit is the code of the price unit (e.g., 'btc', 'eth')"""

    price_unit_amount: Optional[str] = None
    r"""PriceUnitAmount is the amount of the price unit"""

    price_unit_id: Optional[str] = None
    r"""PriceUnitID is the id of the price unit (for CUSTOM type)"""

    price_unit_tiers: Optional[List[PricePriceTier]] = None
    r"""PriceUnitTiers are the tiers for the price unit when BillingModel is TIERED"""

    price_unit_type: Optional[PriceUnitType] = None

    start_date: Optional[str] = None
    r"""StartDate is the start date of the price"""

    status: Optional[Status] = None

    tenant_id: Optional[str] = None

    tier_mode: Optional[BillingTier] = None

    tiers: Optional[List[PricePriceTier]] = None

    transform_quantity: Optional[PriceJSONBTransformQuantity] = None

    trial_period: Optional[int] = None
    r"""TrialPeriod is the number of days for the trial period
    Note: This is only applicable for recurring prices (BILLING_CADENCE_RECURRING)
    """

    type: Optional[PriceType] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "billing_cadence",
                "billing_model",
                "billing_period",
                "billing_period_count",
                "conversion_rate",
                "created_at",
                "created_by",
                "currency",
                "description",
                "display_amount",
                "display_name",
                "display_price_unit_amount",
                "end_date",
                "entity_id",
                "entity_type",
                "environment_id",
                "group_id",
                "id",
                "invoice_cadence",
                "lookup_key",
                "metadata",
                "meter_id",
                "min_quantity",
                "parent_price_id",
                "price_unit",
                "price_unit_amount",
                "price_unit_id",
                "price_unit_tiers",
                "price_unit_type",
                "start_date",
                "status",
                "tenant_id",
                "tier_mode",
                "tiers",
                "transform_quantity",
                "trial_period",
                "type",
                "updated_at",
                "updated_by",
            ]
        )
        nullable_fields = set(["min_quantity"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
