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

from __future__ import annotations
from datetime import datetime
from paygentic_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from paygentic_sdk.utils import FieldMetadata, PathParamMetadata, RequestMetadata
import pydantic
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class UpdateBillableMetricRequestBodyTypedDict(TypedDict):
    description: NotRequired[str]
    r"""Revised explanation of what the metric represents. Sample values: 'Language model token consumption', 'Database storage capacity used', 'Machine learning prediction API calls', 'AI-generated content items'"""
    name: NotRequired[str]
    r"""Updated label for the metric. Sample values: 'LLM Tokens', 'Database Storage', 'Prediction Requests', 'Content Generations'"""
    unit: NotRequired[str]
    r"""Updated measurement unit. Common examples: 'tokens', 'GB', 'requests', 'items', 'hours'"""
    event_type: NotRequired[Nullable[str]]
    r"""CloudEvents type for meter routing."""
    value_property: NotRequired[Nullable[str]]
    r"""JSONPath to extract numeric value from event data."""
    group_by: NotRequired[Nullable[Dict[str, str]]]
    r"""Map of dimension name to JSONPath for group-by queries."""
    event_from: NotRequired[Nullable[datetime]]
    r"""Only count events after this timestamp."""


class UpdateBillableMetricRequestBody(BaseModel):
    description: Optional[str] = None
    r"""Revised explanation of what the metric represents. Sample values: 'Language model token consumption', 'Database storage capacity used', 'Machine learning prediction API calls', 'AI-generated content items'"""

    name: Optional[str] = None
    r"""Updated label for the metric. Sample values: 'LLM Tokens', 'Database Storage', 'Prediction Requests', 'Content Generations'"""

    unit: Optional[str] = None
    r"""Updated measurement unit. Common examples: 'tokens', 'GB', 'requests', 'items', 'hours'"""

    event_type: Annotated[OptionalNullable[str], pydantic.Field(alias="eventType")] = (
        UNSET
    )
    r"""CloudEvents type for meter routing."""

    value_property: Annotated[
        OptionalNullable[str], pydantic.Field(alias="valueProperty")
    ] = UNSET
    r"""JSONPath to extract numeric value from event data."""

    group_by: Annotated[
        OptionalNullable[Dict[str, str]], pydantic.Field(alias="groupBy")
    ] = UNSET
    r"""Map of dimension name to JSONPath for group-by queries."""

    event_from: Annotated[
        OptionalNullable[datetime], pydantic.Field(alias="eventFrom")
    ] = UNSET
    r"""Only count events after this timestamp."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "description",
                "name",
                "unit",
                "eventType",
                "valueProperty",
                "groupBy",
                "eventFrom",
            ]
        )
        nullable_fields = set(["eventType", "valueProperty", "groupBy", "eventFrom"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


class UpdateBillableMetricRequestTypedDict(TypedDict):
    id: str
    request_body: UpdateBillableMetricRequestBodyTypedDict


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

    request_body: Annotated[
        UpdateBillableMetricRequestBody,
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ]


try:
    UpdateBillableMetricRequestBody.model_rebuild()
except NameError:
    pass
