"""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.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoOverrideLineItemRequestTypedDict(TypedDict):
    price_id: str
    r"""PriceID references the plan price to override"""
    amount: NotRequired[str]
    r"""Amount is the new price amount that overrides the original price (optional)"""
    billing_model: NotRequired[BillingModel]
    price_unit_amount: NotRequired[str]
    r"""PriceUnitAmount is the amount of the price unit (for CUSTOM type, FLAT_FEE/PACKAGE billing models)"""
    price_unit_tiers: NotRequired[List[DtoCreatePriceTierTypedDict]]
    r"""PriceUnitTiers are the tiers for the price unit (for CUSTOM type, TIERED billing model)"""
    quantity: NotRequired[str]
    r"""Quantity for this line item (optional)"""
    tier_mode: NotRequired[BillingTier]
    tiers: NotRequired[List[DtoCreatePriceTierTypedDict]]
    r"""Tiers determines the pricing tiers for this line item"""
    transform_quantity: NotRequired[PriceTransformQuantityTypedDict]


class DtoOverrideLineItemRequest(BaseModel):
    price_id: str
    r"""PriceID references the plan price to override"""

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

    billing_model: Optional[BillingModel] = None

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

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

    quantity: Optional[str] = None
    r"""Quantity for this line item (optional)"""

    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",
                "price_unit_amount",
                "price_unit_tiers",
                "quantity",
                "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, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
