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

from __future__ import annotations
from .meta import Meta, MetaTypedDict
from .pagination import Pagination, PaginationTypedDict
from .permission import Permission, PermissionTypedDict
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict
from unkey.py.types import BaseModel, UNSET_SENTINEL


class V2PermissionsListPermissionsResponseBodyTypedDict(TypedDict):
    meta: MetaTypedDict
    r"""Metadata object included in every API response. This provides context about the request and is essential for debugging, audit trails, and support inquiries. The `requestId` is particularly important when troubleshooting issues with the Unkey support team."""
    data: List[PermissionTypedDict]
    r"""Array of permission objects with complete configuration details."""
    pagination: NotRequired[PaginationTypedDict]
    r"""Pagination metadata for list endpoints. Provides information necessary to traverse through large result sets efficiently using cursor-based pagination."""


class V2PermissionsListPermissionsResponseBody(BaseModel):
    meta: Meta
    r"""Metadata object included in every API response. This provides context about the request and is essential for debugging, audit trails, and support inquiries. The `requestId` is particularly important when troubleshooting issues with the Unkey support team."""

    data: List[Permission]
    r"""Array of permission objects with complete configuration details."""

    pagination: Optional[Pagination] = None
    r"""Pagination metadata for list endpoints. Provides information necessary to traverse through large result sets efficiently using cursor-based pagination."""

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