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

from __future__ import annotations
from .pricefeature import PriceFeature, PriceFeatureTypedDict
from datetime import datetime
from paygentic_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


PriceObject = Literal["price",]


PriceModel = Union[
    Literal[
        "standard",
        "dynamic",
        "volume",
        "percentage",
    ],
    UnrecognizedStr,
]


PricePaymentTerm = Union[
    Literal[
        "instant",
        "in_arrears",
        "in_advance",
    ],
    UnrecognizedStr,
]


class PriceTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a price"""
    created_at: datetime
    invoice_display_name: str
    model: PriceModel
    payment_term: PricePaymentTerm
    properties: Dict[str, Any]
    updated_at: datetime
    object: NotRequired[PriceObject]
    billable_metric_id: NotRequired[str]
    fee_id: NotRequired[str]
    r"""The unique identifier for the fee referred to by this price"""
    billing_cadence: NotRequired[Nullable[str]]
    r"""ISO 8601 duration for billing frequency (e.g., P1M for monthly)"""
    currency: NotRequired[str]
    description: NotRequired[str]
    unit_amount: NotRequired[str]
    features: NotRequired[List[PriceFeatureTypedDict]]
    r"""Features associated with this price"""


class Price(BaseModel):
    id: str
    r"""Unique identifier for a price"""

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]

    invoice_display_name: Annotated[str, pydantic.Field(alias="invoiceDisplayName")]

    model: PriceModel

    payment_term: Annotated[PricePaymentTerm, pydantic.Field(alias="paymentTerm")]

    properties: Dict[str, Any]

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]

    object: Optional[PriceObject] = "price"

    billable_metric_id: Annotated[
        Optional[str], pydantic.Field(alias="billableMetricId")
    ] = None

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

    billing_cadence: Annotated[
        OptionalNullable[str], pydantic.Field(alias="billingCadence")
    ] = UNSET
    r"""ISO 8601 duration for billing frequency (e.g., P1M for monthly)"""

    currency: Optional[str] = None

    description: Optional[str] = None

    unit_amount: Annotated[Optional[str], pydantic.Field(alias="unitAmount")] = None

    features: Optional[List[PriceFeature]] = None
    r"""Features associated with this price"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "object",
                "billableMetricId",
                "feeId",
                "billingCadence",
                "currency",
                "description",
                "unitAmount",
                "features",
            ]
        )
        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, serialized.get(n))
            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:
    Price.model_rebuild()
except NameError:
    pass
