"""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
import pydantic
from pydantic import model_serializer
from typing import Dict, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


CreateBillableMetricAggregation = Literal[
    "SUM",
    "COUNT",
    "AVG",
    "MIN",
    "MAX",
    "UNIQUE_COUNT",
    "LATEST",
]
r"""Aggregation calculation method for metric values."""


class CreateBillableMetricRequestTypedDict(TypedDict):
    aggregation: CreateBillableMetricAggregation
    r"""Aggregation calculation method for metric values."""
    description: str
    r"""Explanatory text describing what the metric tracks and how it's used for billing. Sample values: 'Total tokens consumed by Claude language model interactions', 'Gigabytes of cloud storage utilized', 'Count of machine learning inference requests processed', 'Quantity of AI-generated images created', 'Compute hours spent training neural networks', 'Terabytes of data transferred'"""
    merchant_id: str
    r"""Unique identifier for an organization"""
    name: str
    r"""Human-readable label identifying what this metric measures. Sample values: 'Claude Tokens', 'Storage Capacity', 'Model Inference Calls', 'Generated Images', 'Training Compute Hours', 'Data Transfer Volume'"""
    product_id: str
    r"""Unique identifier for a product"""
    unit: str
    r"""Measurement unit used when aggregating this metric's values. Common examples: 'tokens', 'GB', 'calls', 'images', 'hours', 'TB', 'queries', 'requests'"""
    event_type: NotRequired[str]
    r"""CloudEvents type for meter routing. Links this billable metric to the metering service."""
    value_property: NotRequired[str]
    r"""JSONPath to extract numeric value from event data. Required for SUM/AVG/MIN/MAX/LATEST aggregations."""
    group_by: NotRequired[Dict[str, str]]
    r"""Map of dimension name to JSONPath for group-by queries."""
    event_from: NotRequired[datetime]
    r"""Only count events after this timestamp. Used for meter versioning."""


class CreateBillableMetricRequest(BaseModel):
    aggregation: CreateBillableMetricAggregation
    r"""Aggregation calculation method for metric values."""

    description: str
    r"""Explanatory text describing what the metric tracks and how it's used for billing. Sample values: 'Total tokens consumed by Claude language model interactions', 'Gigabytes of cloud storage utilized', 'Count of machine learning inference requests processed', 'Quantity of AI-generated images created', 'Compute hours spent training neural networks', 'Terabytes of data transferred'"""

    merchant_id: Annotated[str, pydantic.Field(alias="merchantId")]
    r"""Unique identifier for an organization"""

    name: str
    r"""Human-readable label identifying what this metric measures. Sample values: 'Claude Tokens', 'Storage Capacity', 'Model Inference Calls', 'Generated Images', 'Training Compute Hours', 'Data Transfer Volume'"""

    product_id: Annotated[str, pydantic.Field(alias="productId")]
    r"""Unique identifier for a product"""

    unit: str
    r"""Measurement unit used when aggregating this metric's values. Common examples: 'tokens', 'GB', 'calls', 'images', 'hours', 'TB', 'queries', 'requests'"""

    event_type: Annotated[Optional[str], pydantic.Field(alias="eventType")] = None
    r"""CloudEvents type for meter routing. Links this billable metric to the metering service."""

    value_property: Annotated[Optional[str], pydantic.Field(alias="valueProperty")] = (
        None
    )
    r"""JSONPath to extract numeric value from event data. Required for SUM/AVG/MIN/MAX/LATEST aggregations."""

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

    event_from: Annotated[Optional[datetime], pydantic.Field(alias="eventFrom")] = None
    r"""Only count events after this timestamp. Used for meter versioning."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_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)

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

        return m


try:
    CreateBillableMetricRequest.model_rebuild()
except NameError:
    pass
