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

    START_DATE = "start_date"
    MINUS_START_DATE = "-start_date"
    END_DATE = "end_date"
    MINUS_END_DATE = "-end_date"
    LATITUDE = "latitude"
    MINUS_LATITUDE = "-latitude"
    LONGITUDE = "longitude"
    MINUS_LONGITUDE = "-longitude"


class ListEventsRequestTypedDict(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"""
    ordering: NotRequired[Nullable[ListEventsOrdering]]
    r"""Ordering field"""
    is_upcoming: NotRequired[Nullable[bool]]
    r"""Filter for upcoming events"""
    page: NotRequired[int]
    r"""Page number"""
    page_size: NotRequired[int]
    r"""Number of items per page"""


class ListEventsRequest(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"""

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

    is_upcoming: Annotated[
        OptionalNullable[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""Filter for upcoming events"""

    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 = [
            "latitude_gte",
            "latitude_lte",
            "longitude_gte",
            "longitude_lte",
            "ordering",
            "is_upcoming",
            "page",
            "page_size",
        ]
        nullable_fields = [
            "latitude_gte",
            "latitude_lte",
            "longitude_gte",
            "longitude_lte",
            "ordering",
            "is_upcoming",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            serialized.pop(k, None)

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
