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

from __future__ import annotations
from .meter_aggregation import MeterAggregation, MeterAggregationTypedDict
from .meter_filter import MeterFilter, MeterFilterTypedDict
from .resetusage import ResetUsage
from .status import Status
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class MeterMeterTypedDict(TypedDict):
    aggregation: NotRequired[MeterAggregationTypedDict]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    environment_id: NotRequired[str]
    r"""EnvironmentID is the environment identifier for the meter"""
    event_name: NotRequired[str]
    r"""EventName is the unique identifier for the event that this meter is tracking
    It is a mandatory field in the events table and hence being used as the primary matching field
    We can have multiple meters tracking the same event but with different filters and aggregation
    """
    filters: NotRequired[List[MeterFilterTypedDict]]
    r"""Filters define the criteria for the meter to be applied on the events before aggregation
    It also defines the possible values on which later the charges will be applied
    """
    id: NotRequired[str]
    r"""ID is the unique identifier for the meter"""
    name: NotRequired[str]
    r"""Name is the display name of the meter"""
    reset_usage: NotRequired[ResetUsage]
    status: NotRequired[Status]
    tenant_id: NotRequired[str]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class MeterMeter(BaseModel):
    aggregation: Optional[MeterAggregation] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    environment_id: Optional[str] = None
    r"""EnvironmentID is the environment identifier for the meter"""

    event_name: Optional[str] = None
    r"""EventName is the unique identifier for the event that this meter is tracking
    It is a mandatory field in the events table and hence being used as the primary matching field
    We can have multiple meters tracking the same event but with different filters and aggregation
    """

    filters: Optional[List[MeterFilter]] = None
    r"""Filters define the criteria for the meter to be applied on the events before aggregation
    It also defines the possible values on which later the charges will be applied
    """

    id: Optional[str] = None
    r"""ID is the unique identifier for the meter"""

    name: Optional[str] = None
    r"""Name is the display name of the meter"""

    reset_usage: Optional[ResetUsage] = None

    status: Optional[Status] = None

    tenant_id: Optional[str] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "aggregation",
                "created_at",
                "created_by",
                "environment_id",
                "event_name",
                "filters",
                "id",
                "name",
                "reset_usage",
                "status",
                "tenant_id",
                "updated_at",
                "updated_by",
            ]
        )
        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
