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

from __future__ import annotations
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 DtoUsageBreakdownItemTypedDict(TypedDict):
    cost: NotRequired[str]
    r"""cost is the cost attributed to this group for the line item"""
    event_count: NotRequired[int]
    r"""event_count is the number of events from this group (optional)"""
    grouped_by: NotRequired[Dict[str, str]]
    r"""grouped_by contains the grouping field values (e.g., {\"source\": \"api\", \"org_id\": \"org123\"})"""
    percentage: NotRequired[str]
    r"""percentage is the percentage of total line item cost from this group (optional)"""
    usage: NotRequired[str]
    r"""usage is the total usage amount from this group (optional, for additional context)"""


class DtoUsageBreakdownItem(BaseModel):
    cost: Optional[str] = None
    r"""cost is the cost attributed to this group for the line item"""

    event_count: Optional[int] = None
    r"""event_count is the number of events from this group (optional)"""

    grouped_by: Optional[Dict[str, str]] = None
    r"""grouped_by contains the grouping field values (e.g., {\"source\": \"api\", \"org_id\": \"org123\"})"""

    percentage: Optional[str] = None
    r"""percentage is the percentage of total line item cost from this group (optional)"""

    usage: Optional[str] = None
    r"""usage is the total usage amount from this group (optional, for additional context)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["cost", "event_count", "grouped_by", "percentage", "usage"]
        )
        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
