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

from __future__ import annotations
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL, UnrecognizedStr
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


PriceFeatureType = Union[
    Literal[
        "metered",
        "static",
        "boolean",
    ],
    UnrecognizedStr,
]


class PriceFeatureFeatureTypedDict(TypedDict):
    key: NotRequired[str]
    name: NotRequired[str]
    type: NotRequired[PriceFeatureType]


class PriceFeatureFeature(BaseModel):
    key: Optional[str] = None

    name: Optional[str] = None

    type: Optional[PriceFeatureType] = None

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class PriceFeatureTypedDict(TypedDict):
    id: str
    feature_id: str
    entitlement_template: Dict[str, Any]
    feature: NotRequired[PriceFeatureFeatureTypedDict]


class PriceFeature(BaseModel):
    id: str

    feature_id: Annotated[str, pydantic.Field(alias="featureId")]

    entitlement_template: Annotated[
        Dict[str, Any], pydantic.Field(alias="entitlementTemplate")
    ]

    feature: Optional[PriceFeatureFeature] = None

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    PriceFeature.model_rebuild()
except NameError:
    pass
