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

from __future__ import annotations
from .pricefeatureinput import PriceFeatureInput, PriceFeatureInputTypedDict
from .priceproperties_union import PricePropertiesUnion, PricePropertiesUnionTypedDict
from paygentic_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


CreatePriceModel = Literal[
    "standard",
    "dynamic",
    "volume",
    "percentage",
]
r"""Pricing calculation model. Required for billable metrics, optional for fees (defaults to 'standard')."""


CreatePricePaymentTerm = Literal[
    "instant",
    "in_arrears",
    "in_advance",
]
r"""Billing timing preference. For billable metrics: 'instant' (charges immediately) or 'in_arrears' (charges at period end). For fees: 'in_advance' (charges upfront) or 'in_arrears' (charges at period end)."""


class CreatePriceRequestTypedDict(TypedDict):
    invoice_display_name: str
    r"""Line item label shown on customer invoices. Sample values: 'Claude Token Consumption', 'Storage Usage (GB)', 'Inference API Calls', 'Image Generation Count', 'Training Compute Hours', 'Data Transfer (TB)'"""
    payment_term: CreatePricePaymentTerm
    r"""Billing timing preference. For billable metrics: 'instant' (charges immediately) or 'in_arrears' (charges at period end). For fees: 'in_advance' (charges upfront) or 'in_arrears' (charges at period end)."""
    properties: PricePropertiesUnionTypedDict
    billable_metric_id: NotRequired[str]
    r"""Unique identifier for a billable metric"""
    fee_id: NotRequired[str]
    r"""The unique identifier for the fee referred to by this price. Either billableMetricId or feeId must be provided."""
    model: NotRequired[CreatePriceModel]
    r"""Pricing calculation model. Required for billable metrics, optional for fees (defaults to 'standard')."""
    billing_cadence: NotRequired[Nullable[str]]
    r"""ISO 8601 duration for recurring charges (e.g., 'P1M' for monthly, 'P1Y' for yearly) or 'P0D' for one-time charges. Required for fees, optional for billable metrics. Sample values: 'P0D' for one-time, 'P1M' for monthly recurring, 'P1Y' for yearly recurring"""
    feature: NotRequired[PriceFeatureInputTypedDict]


class CreatePriceRequest(BaseModel):
    invoice_display_name: Annotated[str, pydantic.Field(alias="invoiceDisplayName")]
    r"""Line item label shown on customer invoices. Sample values: 'Claude Token Consumption', 'Storage Usage (GB)', 'Inference API Calls', 'Image Generation Count', 'Training Compute Hours', 'Data Transfer (TB)'"""

    payment_term: Annotated[CreatePricePaymentTerm, pydantic.Field(alias="paymentTerm")]
    r"""Billing timing preference. For billable metrics: 'instant' (charges immediately) or 'in_arrears' (charges at period end). For fees: 'in_advance' (charges upfront) or 'in_arrears' (charges at period end)."""

    properties: PricePropertiesUnion

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

    fee_id: Annotated[Optional[str], pydantic.Field(alias="feeId")] = None
    r"""The unique identifier for the fee referred to by this price. Either billableMetricId or feeId must be provided."""

    model: Optional[CreatePriceModel] = None
    r"""Pricing calculation model. Required for billable metrics, optional for fees (defaults to 'standard')."""

    billing_cadence: Annotated[
        OptionalNullable[str], pydantic.Field(alias="billingCadence")
    ] = UNSET
    r"""ISO 8601 duration for recurring charges (e.g., 'P1M' for monthly, 'P1Y' for yearly) or 'P0D' for one-time charges. Required for fees, optional for billable metrics. Sample values: 'P0D' for one-time, 'P1M' for monthly recurring, 'P1Y' for yearly recurring"""

    feature: Optional[PriceFeatureInput] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["billableMetricId", "feeId", "model", "billingCadence", "feature"]
        )
        nullable_fields = set(["billingCadence"])
        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


try:
    CreatePriceRequest.model_rebuild()
except NameError:
    pass
