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

from __future__ import annotations
from .billingmodel import BillingModel
from .billingperiod import BillingPeriod
from .billingtier import BillingTier
from .commitmenttype import CommitmentType
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 DtoUpdateSubscriptionLineItemRequestTypedDict(TypedDict):
    amount: NotRequired[str]
    r"""Amount is the new price amount that overrides the original price"""
    billing_model: NotRequired[BillingModel]
    commitment_amount: NotRequired[float]
    r"""Commitment fields"""
    commitment_duration: NotRequired[BillingPeriod]
    commitment_overage_factor: NotRequired[float]
    commitment_quantity: NotRequired[float]
    commitment_true_up_enabled: NotRequired[bool]
    commitment_type: NotRequired[CommitmentType]
    commitment_windowed: NotRequired[bool]
    effective_from: NotRequired[str]
    r"""EffectiveFrom for the existing line item (if not provided, defaults to now)"""
    metadata: NotRequired[Dict[str, str]]
    r"""Metadata for the new line item"""
    tier_mode: NotRequired[BillingTier]
    tiers: NotRequired[List[DtoCreatePriceTierTypedDict]]
    r"""Tiers determines the pricing tiers for this line item"""
    transform_quantity: NotRequired[PriceTransformQuantityTypedDict]


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

    billing_model: Optional[BillingModel] = None

    commitment_amount: Optional[float] = None
    r"""Commitment fields"""

    commitment_duration: Optional[BillingPeriod] = None

    commitment_overage_factor: Optional[float] = None

    commitment_quantity: Optional[float] = None

    commitment_true_up_enabled: Optional[bool] = None

    commitment_type: Optional[CommitmentType] = None

    commitment_windowed: Optional[bool] = None

    effective_from: Optional[str] = None
    r"""EffectiveFrom for the existing line item (if not provided, defaults to now)"""

    metadata: Optional[Dict[str, str]] = None
    r"""Metadata for the new line item"""

    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",
                "commitment_amount",
                "commitment_duration",
                "commitment_overage_factor",
                "commitment_quantity",
                "commitment_true_up_enabled",
                "commitment_type",
                "commitment_windowed",
                "effective_from",
                "metadata",
                "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
