"""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 .dto_createpricetier import DtoCreatePriceTier, DtoCreatePriceTierTypedDict
from .dto_priceunitconfig import DtoPriceUnitConfig, DtoPriceUnitConfigTypedDict
from .invoicecadence import InvoiceCadence
from .price_transformquantity import (
    PriceTransformQuantity,
    PriceTransformQuantityTypedDict,
)
from .pricetype import PriceType
from .priceunittype import PriceUnitType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoSubscriptionPriceCreateRequestTypedDict(TypedDict):
    billing_cadence: BillingCadence
    billing_model: BillingModel
    billing_period: BillingPeriod
    invoice_cadence: InvoiceCadence
    price_unit_type: PriceUnitType
    type: PriceType
    amount: NotRequired[str]
    billing_period_count: NotRequired[int]
    description: NotRequired[str]
    display_name: NotRequired[str]
    end_date: NotRequired[str]
    filter_values: NotRequired[Dict[str, List[str]]]
    lookup_key: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    meter_id: NotRequired[str]
    min_quantity: NotRequired[int]
    price_unit_config: NotRequired[DtoPriceUnitConfigTypedDict]
    start_date: NotRequired[str]
    tier_mode: NotRequired[BillingTier]
    tiers: NotRequired[List[DtoCreatePriceTierTypedDict]]
    transform_quantity: NotRequired[PriceTransformQuantityTypedDict]
    trial_period: NotRequired[int]


class DtoSubscriptionPriceCreateRequest(BaseModel):
    billing_cadence: BillingCadence

    billing_model: BillingModel

    billing_period: BillingPeriod

    invoice_cadence: InvoiceCadence

    price_unit_type: PriceUnitType

    type: PriceType

    amount: Optional[str] = None

    billing_period_count: Optional[int] = None

    description: Optional[str] = None

    display_name: Optional[str] = None

    end_date: Optional[str] = None

    filter_values: Optional[Dict[str, List[str]]] = None

    lookup_key: Optional[str] = None

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

    meter_id: Optional[str] = None

    min_quantity: Optional[int] = None

    price_unit_config: Optional[DtoPriceUnitConfig] = None

    start_date: Optional[str] = None

    tier_mode: Optional[BillingTier] = None

    tiers: Optional[List[DtoCreatePriceTier]] = None

    transform_quantity: Optional[PriceTransformQuantity] = None

    trial_period: Optional[int] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "billing_period_count",
                "description",
                "display_name",
                "end_date",
                "filter_values",
                "lookup_key",
                "metadata",
                "meter_id",
                "min_quantity",
                "price_unit_config",
                "start_date",
                "tier_mode",
                "tiers",
                "transform_quantity",
                "trial_period",
            ]
        )
        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
