"""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, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


SchemasEntitlementObject = Literal["entitlement",]


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


class SchemasEntitlementTypedDict(TypedDict):
    id: str
    r"""Unique identifier for the entitlement."""
    customer_id: str
    r"""Unique identifier for a customer"""
    feature_id: str
    r"""The feature this entitlement grants access to."""
    status: SchemasEntitlementStatus
    r"""Current status of the entitlement."""
    active_from: datetime
    r"""When the entitlement becomes active."""
    config: Nullable[Dict[str, Any]]
    r"""Configuration values for static features."""
    object: NotRequired[SchemasEntitlementObject]
    subscription_id: NotRequired[Nullable[str]]
    r"""The subscription this entitlement is associated with, if any."""
    active_to: NotRequired[Nullable[datetime]]
    r"""When the entitlement expires. Null means no expiration."""
    metadata: NotRequired[Dict[str, str]]
    r"""Additional metadata for the entitlement."""


class SchemasEntitlement(BaseModel):
    id: str
    r"""Unique identifier for the entitlement."""

    customer_id: Annotated[str, pydantic.Field(alias="customerId")]
    r"""Unique identifier for a customer"""

    feature_id: Annotated[str, pydantic.Field(alias="featureId")]
    r"""The feature this entitlement grants access to."""

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

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

    config: Nullable[Dict[str, Any]]
    r"""Configuration values for static features."""

    object: Optional[SchemasEntitlementObject] = "entitlement"

    subscription_id: Annotated[
        OptionalNullable[str], pydantic.Field(alias="subscriptionId")
    ] = UNSET
    r"""The subscription this entitlement is associated with, if any."""

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

    metadata: Optional[Dict[str, str]] = None
    r"""Additional metadata for the entitlement."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["object", "subscriptionId", "activeTo", "metadata"])
        nullable_fields = set(["subscriptionId", "activeTo", "config"])
        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


try:
    SchemasEntitlement.model_rebuild()
except NameError:
    pass
