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

from __future__ import annotations
from .billingperiod import BillingPeriod
from .commitmenttype import CommitmentType
from .dto_subscriptionpricecreaterequest import (
    DtoSubscriptionPriceCreateRequest,
    DtoSubscriptionPriceCreateRequestTypedDict,
)
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreateSubscriptionLineItemRequestTypedDict(TypedDict):
    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]
    display_name: NotRequired[str]
    end_date: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    price: NotRequired[DtoSubscriptionPriceCreateRequestTypedDict]
    price_id: NotRequired[str]
    r"""PriceID references an existing price (plan, addon, or subscription-scoped). Exactly one of price_id or price must be set."""
    quantity: NotRequired[float]
    start_date: NotRequired[str]
    subscription_phase_id: NotRequired[str]


class DtoCreateSubscriptionLineItemRequest(BaseModel):
    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

    display_name: Optional[str] = None

    end_date: Optional[str] = None

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

    price: Optional[DtoSubscriptionPriceCreateRequest] = None

    price_id: Optional[str] = None
    r"""PriceID references an existing price (plan, addon, or subscription-scoped). Exactly one of price_id or price must be set."""

    quantity: Optional[float] = None

    start_date: Optional[str] = None

    subscription_phase_id: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "commitment_amount",
                "commitment_duration",
                "commitment_overage_factor",
                "commitment_quantity",
                "commitment_true_up_enabled",
                "commitment_type",
                "commitment_windowed",
                "display_name",
                "end_date",
                "metadata",
                "price",
                "price_id",
                "quantity",
                "start_date",
                "subscription_phase_id",
            ]
        )
        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
