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

from __future__ import annotations
from .billingperiod import BillingPeriod
from .commitmenttype import CommitmentType
from .invoicecadence import InvoiceCadence
from .price_price import PricePrice, PricePriceTypedDict
from .pricetype import PriceType
from .status import Status
from .subscriptionlineitementitytype import SubscriptionLineItemEntityType
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 SubscriptionSubscriptionLineItemTypedDict(TypedDict):
    billing_period: NotRequired[BillingPeriod]
    billing_period_count: NotRequired[int]
    r"""from price at create; default 1"""
    commitment_amount: NotRequired[str]
    r"""Commitment fields"""
    commitment_duration: NotRequired[BillingPeriod]
    commitment_overage_factor: NotRequired[str]
    commitment_quantity: NotRequired[str]
    commitment_true_up_enabled: NotRequired[bool]
    commitment_type: NotRequired[CommitmentType]
    commitment_windowed: NotRequired[bool]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    currency: NotRequired[str]
    customer_id: NotRequired[str]
    display_name: NotRequired[str]
    end_date: NotRequired[str]
    entity_id: NotRequired[str]
    entity_type: NotRequired[SubscriptionLineItemEntityType]
    environment_id: NotRequired[str]
    id: NotRequired[str]
    invoice_cadence: NotRequired[InvoiceCadence]
    metadata: NotRequired[Dict[str, str]]
    meter_display_name: NotRequired[str]
    meter_id: NotRequired[str]
    plan_display_name: NotRequired[str]
    price: NotRequired[PricePriceTypedDict]
    price_id: NotRequired[str]
    price_type: NotRequired[PriceType]
    price_unit: NotRequired[str]
    price_unit_id: NotRequired[str]
    quantity: NotRequired[str]
    start_date: NotRequired[str]
    status: NotRequired[Status]
    subscription_id: NotRequired[str]
    subscription_phase_id: NotRequired[str]
    tenant_id: NotRequired[str]
    trial_period: NotRequired[int]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class SubscriptionSubscriptionLineItem(BaseModel):
    billing_period: Optional[BillingPeriod] = None

    billing_period_count: Optional[int] = None
    r"""from price at create; default 1"""

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

    commitment_duration: Optional[BillingPeriod] = None

    commitment_overage_factor: Optional[str] = None

    commitment_quantity: Optional[str] = None

    commitment_true_up_enabled: Optional[bool] = None

    commitment_type: Optional[CommitmentType] = None

    commitment_windowed: Optional[bool] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    currency: Optional[str] = None

    customer_id: Optional[str] = None

    display_name: Optional[str] = None

    end_date: Optional[str] = None

    entity_id: Optional[str] = None

    entity_type: Optional[SubscriptionLineItemEntityType] = None

    environment_id: Optional[str] = None

    id: Optional[str] = None

    invoice_cadence: Optional[InvoiceCadence] = None

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

    meter_display_name: Optional[str] = None

    meter_id: Optional[str] = None

    plan_display_name: Optional[str] = None

    price: Optional[PricePrice] = None

    price_id: Optional[str] = None

    price_type: Optional[PriceType] = None

    price_unit: Optional[str] = None

    price_unit_id: Optional[str] = None

    quantity: Optional[str] = None

    start_date: Optional[str] = None

    status: Optional[Status] = None

    subscription_id: Optional[str] = None

    subscription_phase_id: Optional[str] = None

    tenant_id: Optional[str] = None

    trial_period: Optional[int] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "billing_period",
                "billing_period_count",
                "commitment_amount",
                "commitment_duration",
                "commitment_overage_factor",
                "commitment_quantity",
                "commitment_true_up_enabled",
                "commitment_type",
                "commitment_windowed",
                "created_at",
                "created_by",
                "currency",
                "customer_id",
                "display_name",
                "end_date",
                "entity_id",
                "entity_type",
                "environment_id",
                "id",
                "invoice_cadence",
                "metadata",
                "meter_display_name",
                "meter_id",
                "plan_display_name",
                "price",
                "price_id",
                "price_type",
                "price_unit",
                "price_unit_id",
                "quantity",
                "start_date",
                "status",
                "subscription_id",
                "subscription_phase_id",
                "tenant_id",
                "trial_period",
                "updated_at",
                "updated_by",
            ]
        )
        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
