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

from __future__ import annotations
from .billingperiod import BillingPeriod
from .commitmenttype import CommitmentType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class DtoLineItemCommitmentConfigTypedDict(TypedDict):
    commitment_amount: NotRequired[float]
    r"""CommitmentAmount is the minimum amount committed for this line item"""
    commitment_duration: NotRequired[BillingPeriod]
    commitment_quantity: NotRequired[float]
    r"""CommitmentQuantity is the minimum quantity committed for this line item"""
    commitment_type: NotRequired[CommitmentType]
    enable_true_up: NotRequired[bool]
    r"""EnableTrueUp determines if true-up fee should be applied when usage is below commitment"""
    is_window_commitment: NotRequired[bool]
    r"""IsWindowCommitment determines if commitment is applied per window (e.g., per day) rather than per billing period"""
    overage_factor: NotRequired[float]
    r"""OverageFactor is a multiplier applied to usage beyond the commitment"""


class DtoLineItemCommitmentConfig(BaseModel):
    commitment_amount: Optional[float] = None
    r"""CommitmentAmount is the minimum amount committed for this line item"""

    commitment_duration: Optional[BillingPeriod] = None

    commitment_quantity: Optional[float] = None
    r"""CommitmentQuantity is the minimum quantity committed for this line item"""

    commitment_type: Optional[CommitmentType] = None

    enable_true_up: Optional[bool] = None
    r"""EnableTrueUp determines if true-up fee should be applied when usage is below commitment"""

    is_window_commitment: Optional[bool] = None
    r"""IsWindowCommitment determines if commitment is applied per window (e.g., per day) rather than per billing period"""

    overage_factor: Optional[float] = None
    r"""OverageFactor is a multiplier applied to usage beyond the commitment"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "commitment_amount",
                "commitment_duration",
                "commitment_quantity",
                "commitment_type",
                "enable_true_up",
                "is_window_commitment",
                "overage_factor",
            ]
        )
        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
