"""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
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


ActiveEntitlementObject = Literal["entitlement",]


class ActiveEntitlementTypedDict(TypedDict):
    id: NotRequired[str]
    r"""Unique identifier for an entitlement"""
    object: NotRequired[ActiveEntitlementObject]
    billable_metrics: NotRequired[List[str]]
    r"""List of billable metrics that this entitlement covers."""
    customer_id: NotRequired[str]
    r"""Unique identifier for a customer"""
    plan_id: NotRequired[str]
    r"""Unique identifier for a plan"""
    product_id: NotRequired[str]
    r"""Unique identifier for a product"""
    subscription_id: NotRequired[str]
    r"""Unique identifier for a subscription"""
    verified_at: NotRequired[datetime]
    r"""Timestamp when the entitlement was checked."""


class ActiveEntitlement(BaseModel):
    id: Optional[str] = None
    r"""Unique identifier for an entitlement"""

    object: Optional[ActiveEntitlementObject] = "entitlement"

    billable_metrics: Annotated[
        Optional[List[str]], pydantic.Field(alias="billableMetrics")
    ] = None
    r"""List of billable metrics that this entitlement covers."""

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

    plan_id: Annotated[Optional[str], pydantic.Field(alias="planId")] = None
    r"""Unique identifier for a plan"""

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

    subscription_id: Annotated[
        Optional[str], pydantic.Field(alias="subscriptionId")
    ] = None
    r"""Unique identifier for a subscription"""

    verified_at: Annotated[Optional[datetime], pydantic.Field(alias="verifiedAt")] = (
        None
    )
    r"""Timestamp when the entitlement was checked."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "object",
                "billableMetrics",
                "customerId",
                "planId",
                "productId",
                "subscriptionId",
                "verifiedAt",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

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

        return m


try:
    ActiveEntitlement.model_rebuild()
except NameError:
    pass
