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

from __future__ import annotations
from .booking import Booking, BookingTypedDict
import pydantic
from pydantic import model_serializer
from train_travel.types import BaseModel, UNSET_SENTINEL
from train_travel.utils import FieldMetadata, QueryParamMetadata
from typing import Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class GetBookingsRequestTypedDict(TypedDict):
    page: NotRequired[int]
    r"""The page number to return"""
    limit: NotRequired[int]
    r"""The number of items to return per page"""


class GetBookingsRequest(BaseModel):
    page: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 1
    r"""The page number to return"""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 10
    r"""The number of items to return per page"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["page", "limit"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetBookingsXMLLinksTypedDict(TypedDict):
    r"""Links to the next and previous pages of a paginated response."""

    self_: NotRequired[str]
    next: NotRequired[str]
    prev: NotRequired[str]


class GetBookingsXMLLinks(BaseModel):
    r"""Links to the next and previous pages of a paginated response."""

    self_: Optional[str] = None

    next: Optional[str] = None

    prev: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["self", "next", "prev"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetBookingsXMLResponseBodyTypedDict(TypedDict):
    r"""This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS)."""

    data: NotRequired[List[BookingTypedDict]]
    links: NotRequired[GetBookingsXMLLinksTypedDict]


class GetBookingsXMLResponseBody(BaseModel):
    r"""This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS)."""

    data: Optional[List[Booking]] = None

    links: Optional[GetBookingsXMLLinks] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["data", "links"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetBookingsLinksTypedDict(TypedDict):
    r"""Links to the next and previous pages of a paginated response."""

    self_: NotRequired[str]
    next: NotRequired[str]
    prev: NotRequired[str]


class GetBookingsLinks(BaseModel):
    r"""Links to the next and previous pages of a paginated response."""

    self_: Annotated[Optional[str], pydantic.Field(alias="self")] = None

    next: Optional[str] = None

    prev: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["self", "next", "prev"])
        serialized = handler(self)
        m = {}

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

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

        return m


class GetBookingsResponseBodyTypedDict(TypedDict):
    r"""This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS)."""

    data: NotRequired[List[BookingTypedDict]]
    links: NotRequired[GetBookingsLinksTypedDict]


class GetBookingsResponseBody(BaseModel):
    r"""This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS)."""

    data: Optional[List[Booking]] = None

    links: Optional[GetBookingsLinks] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["data", "links"])
        serialized = handler(self)
        m = {}

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

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

        return m


GetBookingsResponseResultTypedDict = TypeAliasType(
    "GetBookingsResponseResultTypedDict", Union[GetBookingsResponseBodyTypedDict, bytes]
)


GetBookingsResponseResult = TypeAliasType(
    "GetBookingsResponseResult", Union[GetBookingsResponseBody, bytes]
)


class GetBookingsResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: GetBookingsResponseResultTypedDict


class GetBookingsResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: GetBookingsResponseResult


try:
    GetBookingsLinks.model_rebuild()
except NameError:
    pass
