"""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, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CreateUsageEventRequestPropertyTypedDict(TypedDict):
    billable_metric_id: str
    r"""Identifier for the consumption metric being reported. Sample metrics: token consumption, storage capacity, inference requests, training hours, data transfer volume"""
    quantity: int
    r"""Measured consumption amount for this metric. Must be a positive whole number. Sample values: 2500 tokens consumed, 42 gigabytes stored, 750 API calls executed, 8 compute hours utilized, 120 images generated"""
    price: NotRequired[str]
    r"""Custom per-unit price in decimal format. The total charge is calculated as price × quantity. Sample values: '0.125' sets $0.125 per unit, '2.50' sets $2.50 per unit. Must be within the minPrice and maxPrice bounds defined for the dynamic price model."""


class CreateUsageEventRequestProperty(BaseModel):
    billable_metric_id: Annotated[str, pydantic.Field(alias="billableMetricId")]
    r"""Identifier for the consumption metric being reported. Sample metrics: token consumption, storage capacity, inference requests, training hours, data transfer volume"""

    quantity: int
    r"""Measured consumption amount for this metric. Must be a positive whole number. Sample values: 2500 tokens consumed, 42 gigabytes stored, 750 API calls executed, 8 compute hours utilized, 120 images generated"""

    price: Optional[str] = None
    r"""Custom per-unit price in decimal format. The total charge is calculated as price × quantity. Sample values: '0.125' sets $0.125 per unit, '2.50' sets $2.50 per unit. Must be within the minPrice and maxPrice bounds defined for the dynamic price model."""

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


class CreateUsageEventRequestTypedDict(TypedDict):
    customer_id: str
    r"""Customer identifier that generated this consumption event. Sample values: 'cus_abc123xyz', 'cus_789def456'"""
    idempotency_key: str
    r"""Unique deduplication key preventing duplicate event processing. Sample values: 'usg_2024_01_15_abc123', 'event_wallet_xyz789', 'consumption_ref_456def'"""
    merchant_id: str
    r"""Merchant organization identifier owning this consumption event. Sample values: 'org_abc123xyz', 'org_789def456'"""
    properties: List[CreateUsageEventRequestPropertyTypedDict]
    timestamp: datetime
    r"""Actual occurrence timestamp for the consumption event in ISO 8601 format. Sample values: '2024-01-15T10:30:00Z', '2024-02-01T14:45:30Z'. Represents when the event occurred, not when Paygentic received it."""
    entitlement_id: NotRequired[str]
    r"""Commitment identifier for this consumption event. Sample values: 'com_abc123xyz', 'com_789def456'"""
    metadata: NotRequired[Dict[str, str]]
    r"""Custom key-value attributes providing context about the consumption event. Sample values: {\"model_name\": \"claude-3-opus\", \"input_tokens\": \"1500\", \"output_tokens\": \"800\"} or {\"storage_tier\": \"premium\", \"data_center\": \"eu-west-1\", \"encryption\": \"enabled\"} or {\"image_resolution\": \"1024x1024\", \"generation_model\": \"stable-diffusion-xl\"}"""


class CreateUsageEventRequest(BaseModel):
    customer_id: Annotated[str, pydantic.Field(alias="customerId")]
    r"""Customer identifier that generated this consumption event. Sample values: 'cus_abc123xyz', 'cus_789def456'"""

    idempotency_key: Annotated[str, pydantic.Field(alias="idempotencyKey")]
    r"""Unique deduplication key preventing duplicate event processing. Sample values: 'usg_2024_01_15_abc123', 'event_wallet_xyz789', 'consumption_ref_456def'"""

    merchant_id: Annotated[str, pydantic.Field(alias="merchantId")]
    r"""Merchant organization identifier owning this consumption event. Sample values: 'org_abc123xyz', 'org_789def456'"""

    properties: List[CreateUsageEventRequestProperty]

    timestamp: datetime
    r"""Actual occurrence timestamp for the consumption event in ISO 8601 format. Sample values: '2024-01-15T10:30:00Z', '2024-02-01T14:45:30Z'. Represents when the event occurred, not when Paygentic received it."""

    entitlement_id: Annotated[Optional[str], pydantic.Field(alias="entitlementId")] = (
        None
    )
    r"""Commitment identifier for this consumption event. Sample values: 'com_abc123xyz', 'com_789def456'"""

    metadata: Optional[Dict[str, str]] = None
    r"""Custom key-value attributes providing context about the consumption event. Sample values: {\"model_name\": \"claude-3-opus\", \"input_tokens\": \"1500\", \"output_tokens\": \"800\"} or {\"storage_tier\": \"premium\", \"data_center\": \"eu-west-1\", \"encryption\": \"enabled\"} or {\"image_resolution\": \"1024x1024\", \"generation_model\": \"stable-diffusion-xl\"}"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["entitlementId", "metadata"])
        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:
    CreateUsageEventRequestProperty.model_rebuild()
except NameError:
    pass
try:
    CreateUsageEventRequest.model_rebuild()
except NameError:
    pass
