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

from __future__ import annotations
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class EntitlementDatumTypedDict(TypedDict):
    billable_metric_id: str
    r"""Unique identifier for a billable metric"""
    quantity: float
    r"""Amount of metric units to pre-authorize. Sample values: 10000 tokens, 500 GB storage, 1000 API calls, 24 compute hours"""
    price: NotRequired[str]
    r"""Optional per-unit price override in decimal dollars for variable-rate pricing. Sample values: '0.000025' sets $0.000025 per token, '0.12' sets $0.12 per GB"""


class EntitlementDatum(BaseModel):
    billable_metric_id: Annotated[str, pydantic.Field(alias="billableMetricId")]
    r"""Unique identifier for a billable metric"""

    quantity: float
    r"""Amount of metric units to pre-authorize. Sample values: 10000 tokens, 500 GB storage, 1000 API calls, 24 compute hours"""

    price: Optional[str] = None
    r"""Optional per-unit price override in decimal dollars for variable-rate pricing. Sample values: '0.000025' sets $0.000025 per token, '0.12' sets $0.12 per GB"""

    @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 CreateEntitlementRequestTypedDict(TypedDict):
    customer_id: str
    r"""Unique identifier for a customer"""
    entitlement_data: List[EntitlementDatumTypedDict]
    r"""Array of consumption metrics with quantities to pre-authorize payment for."""
    merchant_id: str
    r"""Unique identifier for a merchant/organization"""
    max_uses: NotRequired[int]
    r"""Maximum consumption events allowed before expiration (optional). Defaults to 1 for global entitlements, 100 for regional entitlements."""


class CreateEntitlementRequest(BaseModel):
    customer_id: Annotated[str, pydantic.Field(alias="customerId")]
    r"""Unique identifier for a customer"""

    entitlement_data: Annotated[
        List[EntitlementDatum], pydantic.Field(alias="entitlementData")
    ]
    r"""Array of consumption metrics with quantities to pre-authorize payment for."""

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

    max_uses: Annotated[Optional[int], pydantic.Field(alias="maxUses")] = None
    r"""Maximum consumption events allowed before expiration (optional). Defaults to 1 for global entitlements, 100 for regional entitlements."""

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