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

from __future__ import annotations
from .aggregationtype import AggregationType
from .commitmentinfo import CommitmentInfo, CommitmentInfoTypedDict
from .dto_priceresponse import DtoPriceResponse, DtoPriceResponseTypedDict
from .dto_usageanalyticpoint import (
    DtoUsageAnalyticPoint,
    DtoUsageAnalyticPointTypedDict,
)
from .github_com_flexprice_flexprice_internal_domain_addon_addon import (
    GithubComFlexpriceFlexpriceInternalDomainAddonAddon,
    GithubComFlexpriceFlexpriceInternalDomainAddonAddonTypedDict,
)
from .github_com_flexprice_flexprice_internal_domain_feature_feature import (
    GithubComFlexpriceFlexpriceInternalDomainFeatureFeature,
    GithubComFlexpriceFlexpriceInternalDomainFeatureFeatureTypedDict,
)
from .github_com_flexprice_flexprice_internal_domain_plan_plan import (
    GithubComFlexpriceFlexpriceInternalDomainPlanPlan,
    GithubComFlexpriceFlexpriceInternalDomainPlanPlanTypedDict,
)
from .meter_meter import MeterMeter, MeterMeterTypedDict
from .subscription_subscriptionlineitem import (
    SubscriptionSubscriptionLineItem,
    SubscriptionSubscriptionLineItemTypedDict,
)
from .windowsize import WindowSize
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 DtoUsageAnalyticItemTypedDict(TypedDict):
    add_on_id: NotRequired[str]
    addon: NotRequired[GithubComFlexpriceFlexpriceInternalDomainAddonAddonTypedDict]
    aggregation_type: NotRequired[AggregationType]
    commitment_info: NotRequired[CommitmentInfoTypedDict]
    currency: NotRequired[str]
    event_count: NotRequired[int]
    r"""Number of events that contributed to this aggregation"""
    event_name: NotRequired[str]
    feature: NotRequired[
        GithubComFlexpriceFlexpriceInternalDomainFeatureFeatureTypedDict
    ]
    feature_id: NotRequired[str]
    meter: NotRequired[MeterMeterTypedDict]
    meter_id: NotRequired[str]
    r"""Meter ID"""
    name: NotRequired[str]
    plan: NotRequired[GithubComFlexpriceFlexpriceInternalDomainPlanPlanTypedDict]
    plan_id: NotRequired[str]
    points: NotRequired[List[DtoUsageAnalyticPointTypedDict]]
    price: NotRequired[DtoPriceResponseTypedDict]
    price_id: NotRequired[str]
    r"""Price ID used for this usage"""
    properties: NotRequired[Dict[str, str]]
    r"""Stores property values for flexible grouping (e.g., org_id -> \"org123\")"""
    source: NotRequired[str]
    sources: NotRequired[List[str]]
    r"""List of sources when not grouping by source"""
    sub_line_item_id: NotRequired[str]
    r"""Subscription line item ID"""
    subscription_id: NotRequired[str]
    r"""Subscription ID"""
    subscription_line_item: NotRequired[SubscriptionSubscriptionLineItemTypedDict]
    total_cost: NotRequired[str]
    total_usage: NotRequired[str]
    unit: NotRequired[str]
    unit_plural: NotRequired[str]
    window_size: NotRequired[WindowSize]


class DtoUsageAnalyticItem(BaseModel):
    add_on_id: Optional[str] = None

    addon: Optional[GithubComFlexpriceFlexpriceInternalDomainAddonAddon] = None

    aggregation_type: Optional[AggregationType] = None

    commitment_info: Optional[CommitmentInfo] = None

    currency: Optional[str] = None

    event_count: Optional[int] = None
    r"""Number of events that contributed to this aggregation"""

    event_name: Optional[str] = None

    feature: Optional[GithubComFlexpriceFlexpriceInternalDomainFeatureFeature] = None

    feature_id: Optional[str] = None

    meter: Optional[MeterMeter] = None

    meter_id: Optional[str] = None
    r"""Meter ID"""

    name: Optional[str] = None

    plan: Optional[GithubComFlexpriceFlexpriceInternalDomainPlanPlan] = None

    plan_id: Optional[str] = None

    points: Optional[List[DtoUsageAnalyticPoint]] = None

    price: Optional[DtoPriceResponse] = None

    price_id: Optional[str] = None
    r"""Price ID used for this usage"""

    properties: Optional[Dict[str, str]] = None
    r"""Stores property values for flexible grouping (e.g., org_id -> \"org123\")"""

    source: Optional[str] = None

    sources: Optional[List[str]] = None
    r"""List of sources when not grouping by source"""

    sub_line_item_id: Optional[str] = None
    r"""Subscription line item ID"""

    subscription_id: Optional[str] = None
    r"""Subscription ID"""

    subscription_line_item: Optional[SubscriptionSubscriptionLineItem] = None

    total_cost: Optional[str] = None

    total_usage: Optional[str] = None

    unit: Optional[str] = None

    unit_plural: Optional[str] = None

    window_size: Optional[WindowSize] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "add_on_id",
                "addon",
                "aggregation_type",
                "commitment_info",
                "currency",
                "event_count",
                "event_name",
                "feature",
                "feature_id",
                "meter",
                "meter_id",
                "name",
                "plan",
                "plan_id",
                "points",
                "price",
                "price_id",
                "properties",
                "source",
                "sources",
                "sub_line_item_id",
                "subscription_id",
                "subscription_line_item",
                "total_cost",
                "total_usage",
                "unit",
                "unit_plural",
                "window_size",
            ]
        )
        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
