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

from __future__ import annotations
from .grant import Grant, GrantTypedDict
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListEntitlementGrantsRequestTypedDict(TypedDict):
    entitlement_id: str
    r"""The unique identifier of the entitlement."""
    limit: NotRequired[int]
    r"""Maximum number of grants to return per page."""
    offset: NotRequired[int]
    r"""Number of grants to skip."""
    include_voided: NotRequired[bool]
    r"""When true, voided grants are included in the response."""


class ListEntitlementGrantsRequest(BaseModel):
    entitlement_id: Annotated[
        str,
        pydantic.Field(alias="entitlementId"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]
    r"""The unique identifier of the entitlement."""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 20
    r"""Maximum number of grants to return per page."""

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0
    r"""Number of grants to skip."""

    include_voided: Annotated[
        Optional[bool],
        pydantic.Field(alias="includeVoided"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = False
    r"""When true, voided grants are included in the response."""

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


ListEntitlementGrantsObject = Literal["list",]


class ListEntitlementGrantsResponseTypedDict(TypedDict):
    r"""Successfully retrieved the list of grants."""

    data: List[GrantTypedDict]
    pagination: OffsetPaginationTypedDict
    r"""Offset-based pagination response."""
    object: NotRequired[ListEntitlementGrantsObject]


class ListEntitlementGrantsResponse(BaseModel):
    r"""Successfully retrieved the list of grants."""

    data: List[Grant]

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

    object: Optional[ListEntitlementGrantsObject] = "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
