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

from __future__ import annotations
from .price_price import PricePrice, PricePriceTypedDict
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoSubscriptionUsageByMetersResponseTypedDict(TypedDict):
    amount: NotRequired[float]
    currency: NotRequired[str]
    display_amount: NotRequired[str]
    filter_values: NotRequired[Dict[str, List[str]]]
    is_overage: NotRequired[bool]
    r"""Whether this charge is at overage rate"""
    meter_display_name: NotRequired[str]
    meter_id: NotRequired[str]
    overage_factor: NotRequired[float]
    r"""Factor applied to this charge if in overage"""
    price: NotRequired[PricePriceTypedDict]
    quantity: NotRequired[float]
    subscription_line_item_id: NotRequired[str]
    r"""For feature_usage: direct match by sub_line_item_id"""


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

    currency: Optional[str] = None

    display_amount: Optional[str] = None

    filter_values: Optional[Dict[str, List[str]]] = None

    is_overage: Optional[bool] = None
    r"""Whether this charge is at overage rate"""

    meter_display_name: Optional[str] = None

    meter_id: Optional[str] = None

    overage_factor: Optional[float] = None
    r"""Factor applied to this charge if in overage"""

    price: Optional[PricePrice] = None

    quantity: Optional[float] = None

    subscription_line_item_id: Optional[str] = None
    r"""For feature_usage: direct match by sub_line_item_id"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "currency",
                "display_amount",
                "filter_values",
                "is_overage",
                "meter_display_name",
                "meter_id",
                "overage_factor",
                "price",
                "quantity",
                "subscription_line_item_id",
            ]
        )
        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
