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

from __future__ import annotations
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


WindowSize = Literal[
    "MINUTE",
    "HOUR",
    "DAY",
]
r"""Time bucket granularity"""


class GetBillableMetricMeterRequestTypedDict(TypedDict):
    id: str
    from_: datetime
    r"""Start of query window (ISO 8601)"""
    to: datetime
    r"""End of query window (ISO 8601)"""
    subject: NotRequired[str]
    r"""Filter by customer/user ID"""
    window_size: NotRequired[WindowSize]
    r"""Time bucket granularity"""
    filter_group_by: NotRequired[str]
    r"""JSON-encoded dimension filter (e.g. {\"key\":\"value\"})"""
    group_by: NotRequired[str]
    r"""Comma-separated dimension keys"""


class GetBillableMetricMeterRequest(BaseModel):
    id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]

    from_: Annotated[
        datetime,
        pydantic.Field(alias="from"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""Start of query window (ISO 8601)"""

    to: Annotated[
        datetime, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]
    r"""End of query window (ISO 8601)"""

    subject: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by customer/user ID"""

    window_size: Annotated[
        Optional[WindowSize],
        pydantic.Field(alias="windowSize"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Time bucket granularity"""

    filter_group_by: Annotated[
        Optional[str],
        pydantic.Field(alias="filterGroupBy"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""JSON-encoded dimension filter (e.g. {\"key\":\"value\"})"""

    group_by: Annotated[
        Optional[str],
        pydantic.Field(alias="groupBy"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Comma-separated dimension keys"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["subject", "windowSize", "filterGroupBy", "groupBy"])
        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
