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

from __future__ import annotations
from .listorganizationmembersresponse import (
    ListOrganizationMembersResponse,
    ListOrganizationMembersResponseTypedDict,
)
from factify.types import BaseModel, UNSET_SENTINEL
from factify.utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Awaitable, Callable, Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class ListOrganizationMembersRequestTypedDict(TypedDict):
    organization_id: str
    r"""Organization to list members for.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """
    page_token: NotRequired[str]
    r"""Opaque pagination token from a previous response."""
    page_size: NotRequired[int]
    r"""Maximum number of items to return per page (1-100). Default: 50."""


class ListOrganizationMembersRequest(BaseModel):
    organization_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Organization to list members for.
    Pattern: org_[0-9a-hjkmnp-tv-z]{26}
    """

    page_token: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Opaque pagination token from a previous response."""

    page_size: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Maximum number of items to return per page (1-100). Default: 50."""

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


class ListOrganizationMembersResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: ListOrganizationMembersResponseTypedDict


class ListOrganizationMembersResponseResponse(BaseModel):
    next: Union[
        Callable[[], Optional[ListOrganizationMembersResponseResponse]],
        Callable[[], Awaitable[Optional[ListOrganizationMembersResponseResponse]]],
    ]

    headers: Dict[str, List[str]]

    result: ListOrganizationMembersResponse
