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

from __future__ import annotations
from .dto_subscriptionusagebymetersresponse import (
    DtoSubscriptionUsageByMetersResponse,
    DtoSubscriptionUsageByMetersResponseTypedDict,
)
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoGetUsageBySubscriptionResponseTypedDict(TypedDict):
    amount: NotRequired[float]
    charges: NotRequired[List[DtoSubscriptionUsageByMetersResponseTypedDict]]
    commitment_amount: NotRequired[float]
    commitment_utilized: NotRequired[float]
    r"""Amount of commitment used"""
    currency: NotRequired[str]
    display_amount: NotRequired[str]
    end_time: NotRequired[str]
    has_overage: NotRequired[bool]
    r"""Whether any usage exceeded commitment"""
    overage_amount: NotRequired[float]
    r"""Amount charged at overage rate"""
    overage_factor: NotRequired[float]
    start_time: NotRequired[str]


class DtoGetUsageBySubscriptionResponse(BaseModel):
    amount: Optional[float] = None

    charges: Optional[List[DtoSubscriptionUsageByMetersResponse]] = None

    commitment_amount: Optional[float] = None

    commitment_utilized: Optional[float] = None
    r"""Amount of commitment used"""

    currency: Optional[str] = None

    display_amount: Optional[str] = None

    end_time: Optional[str] = None

    has_overage: Optional[bool] = None
    r"""Whether any usage exceeded commitment"""

    overage_amount: Optional[float] = None
    r"""Amount charged at overage rate"""

    overage_factor: Optional[float] = None

    start_time: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "charges",
                "commitment_amount",
                "commitment_utilized",
                "currency",
                "display_amount",
                "end_time",
                "has_overage",
                "overage_amount",
                "overage_factor",
                "start_time",
            ]
        )
        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
