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

from __future__ import annotations
from enum import Enum
from owasp_nest.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from owasp_nest.utils import FieldMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class ListCommitteesOrdering(str, Enum):
    r"""Ordering field"""

    CREATED_AT = "created_at"
    MINUS_CREATED_AT = "-created_at"
    UPDATED_AT = "updated_at"
    MINUS_UPDATED_AT = "-updated_at"


class ListCommitteesRequestTypedDict(TypedDict):
    ordering: NotRequired[Nullable[ListCommitteesOrdering]]
    r"""Ordering field"""
    page: NotRequired[int]
    r"""Page number"""
    page_size: NotRequired[int]
    r"""Number of items per page"""


class ListCommitteesRequest(BaseModel):
    ordering: Annotated[
        OptionalNullable[ListCommitteesOrdering],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Ordering field"""

    page: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 1
    r"""Page number"""

    page_size: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 100
    r"""Number of items per page"""

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