"""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 ListChaptersOrdering(str, Enum):
    r"""Ordering field"""

    CREATED_AT = "created_at"
    MINUS_CREATED_AT = "-created_at"
    UPDATED_AT = "updated_at"
    MINUS_UPDATED_AT = "-updated_at"
    LATITUDE = "latitude"
    MINUS_LATITUDE = "-latitude"
    LONGITUDE = "longitude"
    MINUS_LONGITUDE = "-longitude"


class ListChaptersRequestTypedDict(TypedDict):
    latitude_gte: NotRequired[Nullable[float]]
    r"""Latitude greater than or equal to"""
    latitude_lte: NotRequired[Nullable[float]]
    r"""Latitude less than or equal to"""
    longitude_gte: NotRequired[Nullable[float]]
    r"""Longitude greater than or equal to"""
    longitude_lte: NotRequired[Nullable[float]]
    r"""Longitude less than or equal to"""
    country: NotRequired[Nullable[str]]
    r"""Country of the chapter"""
    ordering: NotRequired[Nullable[ListChaptersOrdering]]
    r"""Ordering field"""
    page: NotRequired[int]
    r"""Page number"""
    page_size: NotRequired[int]
    r"""Number of items per page"""


class ListChaptersRequest(BaseModel):
    latitude_gte: Annotated[
        OptionalNullable[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Latitude greater than or equal to"""

    latitude_lte: Annotated[
        OptionalNullable[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Latitude less than or equal to"""

    longitude_gte: Annotated[
        OptionalNullable[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Longitude greater than or equal to"""

    longitude_lte: Annotated[
        OptionalNullable[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Longitude less than or equal to"""

    country: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Country of the chapter"""

    ordering: Annotated[
        OptionalNullable[ListChaptersOrdering],
        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(
            [
                "latitude_gte",
                "latitude_lte",
                "longitude_gte",
                "longitude_lte",
                "country",
                "ordering",
                "page",
                "page_size",
            ]
        )
        nullable_fields = set(
            [
                "latitude_gte",
                "latitude_lte",
                "longitude_gte",
                "longitude_lte",
                "country",
                "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
