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

from __future__ import annotations
from .dto_costpoint import DtoCostPoint, DtoCostPointTypedDict
from .meter_meter import MeterMeter, MeterMeterTypedDict
from .price_price import PricePrice, PricePriceTypedDict
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCostAnalyticItemTypedDict(TypedDict):
    cost_by_period: NotRequired[List[DtoCostPointTypedDict]]
    r"""Breakdown"""
    costsheet_id: NotRequired[str]
    currency: NotRequired[str]
    r"""Metadata"""
    customer_id: NotRequired[str]
    external_customer_id: NotRequired[str]
    meter: NotRequired[MeterMeterTypedDict]
    meter_id: NotRequired[str]
    meter_name: NotRequired[str]
    price: NotRequired[PricePriceTypedDict]
    price_id: NotRequired[str]
    properties: NotRequired[Dict[str, str]]
    source: NotRequired[str]
    total_cost: NotRequired[str]
    r"""Aggregated metrics"""
    total_events: NotRequired[int]
    total_quantity: NotRequired[str]


class DtoCostAnalyticItem(BaseModel):
    cost_by_period: Optional[List[DtoCostPoint]] = None
    r"""Breakdown"""

    costsheet_id: Optional[str] = None

    currency: Optional[str] = None
    r"""Metadata"""

    customer_id: Optional[str] = None

    external_customer_id: Optional[str] = None

    meter: Optional[MeterMeter] = None

    meter_id: Optional[str] = None

    meter_name: Optional[str] = None

    price: Optional[PricePrice] = None

    price_id: Optional[str] = None

    properties: Optional[Dict[str, str]] = None

    source: Optional[str] = None

    total_cost: Optional[str] = None
    r"""Aggregated metrics"""

    total_events: Optional[int] = None

    total_quantity: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "cost_by_period",
                "costsheet_id",
                "currency",
                "customer_id",
                "external_customer_id",
                "meter",
                "meter_id",
                "meter_name",
                "price",
                "price_id",
                "properties",
                "source",
                "total_cost",
                "total_events",
                "total_quantity",
            ]
        )
        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
