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

from __future__ import annotations
from .billingmodel import BillingModel
from .billingtier import BillingTier
from .dto_createpricetier import DtoCreatePriceTier, DtoCreatePriceTierTypedDict
from .price_transformquantity import (
    PriceTransformQuantity,
    PriceTransformQuantityTypedDict,
)
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoUpdatePriceRequestTypedDict(TypedDict):
    amount: NotRequired[str]
    r"""Amount is the new price amount that overrides the original price (optional)"""
    billing_model: NotRequired[BillingModel]
    description: NotRequired[str]
    display_name: NotRequired[str]
    effective_from: NotRequired[str]
    group_id: NotRequired[str]
    r"""GroupID is the id of the group to update the price in"""
    lookup_key: NotRequired[str]
    r"""All price fields that can be updated
    Non-critical fields (can be updated directly)
    """
    metadata: NotRequired[Dict[str, str]]
    price_unit_amount: NotRequired[str]
    r"""PriceUnitAmount is the price unit amount (for CUSTOM price unit type, FLAT_FEE/PACKAGE billing models)"""
    price_unit_tiers: NotRequired[List[DtoCreatePriceTierTypedDict]]
    r"""PriceUnitTiers are the price unit tiers (for CUSTOM price unit type, TIERED billing model)"""
    tier_mode: NotRequired[BillingTier]
    tiers: NotRequired[List[DtoCreatePriceTierTypedDict]]
    r"""Tiers determines the pricing tiers for this line item"""
    transform_quantity: NotRequired[PriceTransformQuantityTypedDict]


class DtoUpdatePriceRequest(BaseModel):
    amount: Optional[str] = None
    r"""Amount is the new price amount that overrides the original price (optional)"""

    billing_model: Optional[BillingModel] = None

    description: Optional[str] = None

    display_name: Optional[str] = None

    effective_from: Optional[str] = None

    group_id: Optional[str] = None
    r"""GroupID is the id of the group to update the price in"""

    lookup_key: Optional[str] = None
    r"""All price fields that can be updated
    Non-critical fields (can be updated directly)
    """

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

    price_unit_amount: Optional[str] = None
    r"""PriceUnitAmount is the price unit amount (for CUSTOM price unit type, FLAT_FEE/PACKAGE billing models)"""

    price_unit_tiers: Optional[List[DtoCreatePriceTier]] = None
    r"""PriceUnitTiers are the price unit tiers (for CUSTOM price unit type, TIERED billing model)"""

    tier_mode: Optional[BillingTier] = None

    tiers: Optional[List[DtoCreatePriceTier]] = None
    r"""Tiers determines the pricing tiers for this line item"""

    transform_quantity: Optional[PriceTransformQuantity] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "billing_model",
                "description",
                "display_name",
                "effective_from",
                "group_id",
                "lookup_key",
                "metadata",
                "price_unit_amount",
                "price_unit_tiers",
                "tier_mode",
                "tiers",
                "transform_quantity",
            ]
        )
        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
