"""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,
)
from paygentic_sdk.utils import FieldMetadata, PathParamMetadata, RequestMetadata
import pydantic
from pydantic import model_serializer
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


UpdatePriceModel = Literal[
    "standard",
    "dynamic",
    "volume",
    "percentage",
]
r"""The pricing model to be used, which can be standard, dynamic, volume-based, or percentage-based."""


UpdatePricePaymentTerm = 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 UpdatePriceRequestBodyTypedDict(TypedDict):
    billable_metric_id: NotRequired[str]
    r"""Unique identifier for a billable metric"""
    invoice_display_name: NotRequired[str]
    r"""Updated invoice line item label. Sample values: 'LLM Token Usage', 'Storage Charges', 'API Call Fees'"""
    model: NotRequired[UpdatePriceModel]
    r"""The pricing model to be used, which can be standard, dynamic, volume-based, or percentage-based."""
    properties: NotRequired[PricePropertiesUnionTypedDict]
    payment_term: NotRequired[UpdatePricePaymentTerm]
    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)."""
    billing_cadence: NotRequired[Nullable[str]]
    r"""ISO 8601 duration for recurring fees (e.g., 'P1M' for monthly, 'P1Y' for yearly, or 'P0D' for one-time)"""
    feature: NotRequired[Nullable[PriceFeatureInputTypedDict]]
    r"""Feature to associate. Set to null to remove existing feature. Omit to leave unchanged."""


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

    invoice_display_name: Annotated[
        Optional[str], pydantic.Field(alias="invoiceDisplayName")
    ] = None
    r"""Updated invoice line item label. Sample values: 'LLM Token Usage', 'Storage Charges', 'API Call Fees'"""

    model: Optional[UpdatePriceModel] = None
    r"""The pricing model to be used, which can be standard, dynamic, volume-based, or percentage-based."""

    properties: Optional[PricePropertiesUnion] = None

    payment_term: Annotated[
        Optional[UpdatePricePaymentTerm], pydantic.Field(alias="paymentTerm")
    ] = None
    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)."""

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

    feature: OptionalNullable[PriceFeatureInput] = UNSET
    r"""Feature to associate. Set to null to remove existing feature. Omit to leave unchanged."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "billableMetricId",
                "invoiceDisplayName",
                "model",
                "properties",
                "paymentTerm",
                "billingCadence",
                "feature",
            ]
        )
        nullable_fields = set(["billingCadence", "feature"])
        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 UpdatePriceRequestTypedDict(TypedDict):
    id: str
    r"""The unique identifier of the price"""
    request_body: UpdatePriceRequestBodyTypedDict


class UpdatePriceRequest(BaseModel):
    id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""The unique identifier of the price"""

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


try:
    UpdatePriceRequestBody.model_rebuild()
except NameError:
    pass
