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

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


FeatureObject = Literal["feature",]


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


class FeatureTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a feature"""
    key: str
    name: str
    type: FeatureType
    merchant_id: str
    r"""Unique identifier for an organization"""
    product_id: str
    r"""Unique identifier for a product"""
    metadata: Dict[str, str]
    created_at: datetime
    r"""Timestamp when the feature was created"""
    updated_at: datetime
    r"""Timestamp when the feature was last updated"""
    object: NotRequired[FeatureObject]


class Feature(BaseModel):
    id: str
    r"""Unique identifier for a feature"""

    key: str

    name: str

    type: FeatureType

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

    product_id: Annotated[str, pydantic.Field(alias="productId")]
    r"""Unique identifier for a product"""

    metadata: Dict[str, str]

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]
    r"""Timestamp when the feature was created"""

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]
    r"""Timestamp when the feature was last updated"""

    object: Optional[FeatureObject] = "feature"

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