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

from __future__ import annotations
from .entitlementaccessresult import (
    EntitlementAccessResult,
    EntitlementAccessResultTypedDict,
)
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListEntitlementsRequestTypedDict(TypedDict):
    customer_id: str
    r"""The unique identifier of the customer to retrieve entitlements for."""
    feature_key: NotRequired[str]
    r"""Filter results to a specific feature by its key. When specified, `productId` is also required. Use this to check access to a single feature."""
    product_id: NotRequired[str]
    r"""Filter results to entitlements for a specific product. Required when `featureKey` is specified since feature keys are scoped to products."""
    subscription_id: NotRequired[str]
    r"""Filter results to entitlements for a specific subscription."""
    limit: NotRequired[int]
    r"""Maximum number of entitlements to return per page. Use with `offset` for pagination."""
    offset: NotRequired[int]
    r"""Number of entitlements to skip. Use with `limit` for pagination through large result sets."""


class ListEntitlementsRequest(BaseModel):
    customer_id: Annotated[
        str,
        pydantic.Field(alias="customerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""The unique identifier of the customer to retrieve entitlements for."""

    feature_key: Annotated[
        Optional[str],
        pydantic.Field(alias="featureKey"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter results to a specific feature by its key. When specified, `productId` is also required. Use this to check access to a single feature."""

    product_id: Annotated[
        Optional[str],
        pydantic.Field(alias="productId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter results to entitlements for a specific product. Required when `featureKey` is specified since feature keys are scoped to products."""

    subscription_id: Annotated[
        Optional[str],
        pydantic.Field(alias="subscriptionId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter results to entitlements for a specific subscription."""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 10
    r"""Maximum number of entitlements to return per page. Use with `offset` for pagination."""

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0
    r"""Number of entitlements to skip. Use with `limit` for pagination through large result sets."""

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


ListEntitlementsObject = Literal["list",]


class ListEntitlementsResponseTypedDict(TypedDict):
    r"""Successfully retrieved the list of entitlements for the customer."""

    data: List[EntitlementAccessResultTypedDict]
    r"""Array of entitlement access results."""
    pagination: OffsetPaginationTypedDict
    r"""Offset-based pagination response."""
    object: NotRequired[ListEntitlementsObject]


class ListEntitlementsResponse(BaseModel):
    r"""Successfully retrieved the list of entitlements for the customer."""

    data: List[EntitlementAccessResult]
    r"""Array of entitlement access results."""

    pagination: OffsetPagination
    r"""Offset-based pagination response."""

    object: Optional[ListEntitlementsObject] = "list"

    @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
