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

from __future__ import annotations
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, Literal, Union
from typing_extensions import Annotated, NotRequired, TypedDict


FeatureTypeEnum = Union[
    Literal[
        "boolean",
        "static",
        "metered",
    ],
    UnrecognizedStr,
]
r"""The type of feature: `boolean` (on/off), `static` (with config), or `metered` (usage-based)."""


EntitlementAccessResultStatus = Union[
    Literal[
        "active",
        "canceled",
        "expired",
    ],
    UnrecognizedStr,
]
r"""Current status of the entitlement."""


class EntitlementAccessResultTypedDict(TypedDict):
    r"""A customer's entitlement to a specific feature."""

    has_access: bool
    r"""Whether the customer currently has active access to this feature."""
    feature_key: str
    r"""The unique key identifying the feature."""
    feature_type: FeatureTypeEnum
    r"""The type of feature: `boolean` (on/off), `static` (with config), or `metered` (usage-based)."""
    entitlement_id: str
    r"""Unique identifier for this entitlement."""
    product_id: str
    r"""Unique identifier for a product"""
    active_from: datetime
    r"""When the entitlement becomes active."""
    status: EntitlementAccessResultStatus
    r"""Current status of the entitlement."""
    config: NotRequired[Nullable[Dict[str, Any]]]
    r"""Configuration values for `static` features. Null for other types."""
    active_to: NotRequired[Nullable[datetime]]
    r"""When the entitlement expires. Null means no expiration."""


class EntitlementAccessResult(BaseModel):
    r"""A customer's entitlement to a specific feature."""

    has_access: Annotated[bool, pydantic.Field(alias="hasAccess")]
    r"""Whether the customer currently has active access to this feature."""

    feature_key: Annotated[str, pydantic.Field(alias="featureKey")]
    r"""The unique key identifying the feature."""

    feature_type: Annotated[FeatureTypeEnum, pydantic.Field(alias="featureType")]
    r"""The type of feature: `boolean` (on/off), `static` (with config), or `metered` (usage-based)."""

    entitlement_id: Annotated[str, pydantic.Field(alias="entitlementId")]
    r"""Unique identifier for this entitlement."""

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

    active_from: Annotated[datetime, pydantic.Field(alias="activeFrom")]
    r"""When the entitlement becomes active."""

    status: EntitlementAccessResultStatus
    r"""Current status of the entitlement."""

    config: OptionalNullable[Dict[str, Any]] = UNSET
    r"""Configuration values for `static` features. Null for other types."""

    active_to: Annotated[
        OptionalNullable[datetime], pydantic.Field(alias="activeTo")
    ] = UNSET
    r"""When the entitlement expires. Null means no expiration."""

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