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

from __future__ import annotations
from .directorymemberproperties import DirectoryMemberProperties
from .directoryresponseformat import DirectoryResponseFormat
from .orderbydirection import OrderByDirection
from pydantic import model_serializer
from syllable_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from syllable_sdk.utils import FieldMetadata, QueryParamMetadata
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class DirectoryMemberListRequestTypedDict(TypedDict):
    response_format: NotRequired[DirectoryResponseFormat]
    r"""Directory response format: normalized (default) strips @hours and formats times; raw returns stored @hours values."""
    page: NotRequired[Nullable[int]]
    r"""Page number (0-based)"""
    limit: NotRequired[int]
    r"""Items per page"""
    search_fields: NotRequired[List[DirectoryMemberProperties]]
    r"""Fields to search; aligns with search_field_values"""
    search_field_values: NotRequired[List[str]]
    r"""Values for search_fields in matching order"""
    order_by: NotRequired[Nullable[DirectoryMemberProperties]]
    r"""Field to order results by"""
    order_by_direction: NotRequired[Nullable[OrderByDirection]]
    r"""Direction to order results"""
    fields: NotRequired[Nullable[List[DirectoryMemberProperties]]]
    r"""Fields to include in response"""
    start_datetime: NotRequired[Nullable[str]]
    r"""Start datetime for filtering results"""
    end_datetime: NotRequired[Nullable[str]]
    r"""End datetime for filtering results"""


class DirectoryMemberListRequest(BaseModel):
    response_format: Annotated[
        Optional[DirectoryResponseFormat],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Directory response format: normalized (default) strips @hours and formats times; raw returns stored @hours values."""

    page: Annotated[
        OptionalNullable[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Page number (0-based)"""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 25
    r"""Items per page"""

    search_fields: Annotated[
        Optional[List[DirectoryMemberProperties]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Fields to search; aligns with search_field_values"""

    search_field_values: Annotated[
        Optional[List[str]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Values for search_fields in matching order"""

    order_by: Annotated[
        OptionalNullable[DirectoryMemberProperties],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Field to order results by"""

    order_by_direction: Annotated[
        OptionalNullable[OrderByDirection],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Direction to order results"""

    fields: Annotated[
        OptionalNullable[List[DirectoryMemberProperties]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Fields to include in response"""

    start_datetime: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Start datetime for filtering results"""

    end_datetime: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""End datetime for filtering results"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "response_format",
                "page",
                "limit",
                "search_fields",
                "search_field_values",
                "order_by",
                "order_by_direction",
                "fields",
                "start_datetime",
                "end_datetime",
            ]
        )
        nullable_fields = set(
            [
                "page",
                "order_by",
                "order_by_direction",
                "fields",
                "start_datetime",
                "end_datetime",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
