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

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


class CommitmentInfoTypedDict(TypedDict):
    amount: NotRequired[str]
    computed_commitment_utilized_amount: NotRequired[str]
    computed_overage_amount: NotRequired[str]
    computed_true_up_amount: NotRequired[str]
    r"""total_cost = computed_commitment_utilized_amount + computed_overage_amount + computed_true_up_amount"""
    duration: NotRequired[BillingPeriod]
    is_windowed: NotRequired[bool]
    overage_factor: NotRequired[str]
    quantity: NotRequired[str]
    r"""Only used for quantity-based commitments"""
    true_up_enabled: NotRequired[bool]
    type: NotRequired[CommitmentType]


class CommitmentInfo(BaseModel):
    amount: Optional[str] = None

    computed_commitment_utilized_amount: Optional[str] = None

    computed_overage_amount: Optional[str] = None

    computed_true_up_amount: Optional[str] = None
    r"""total_cost = computed_commitment_utilized_amount + computed_overage_amount + computed_true_up_amount"""

    duration: Optional[BillingPeriod] = None

    is_windowed: Optional[bool] = None

    overage_factor: Optional[str] = None

    quantity: Optional[str] = None
    r"""Only used for quantity-based commitments"""

    true_up_enabled: Optional[bool] = None

    type: Optional[CommitmentType] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "computed_commitment_utilized_amount",
                "computed_overage_amount",
                "computed_true_up_amount",
                "duration",
                "is_windowed",
                "overage_factor",
                "quantity",
                "true_up_enabled",
                "type",
            ]
        )
        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
