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

from __future__ import annotations
from .trip import Trip, TripTypedDict
from datetime import datetime
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 GetTripsRequestTypedDict(TypedDict):
    origin: str
    r"""The ID of the origin station"""
    destination: str
    r"""The ID of the destination station"""
    date_: datetime
    r"""The date and time of the trip in ISO 8601 format in origin station's timezone."""
    page: NotRequired[int]
    r"""The page number to return"""
    limit: NotRequired[int]
    r"""The number of items to return per page"""
    bicycles: NotRequired[bool]
    r"""Only return trips where bicycles are known to be allowed"""
    dogs: NotRequired[bool]
    r"""Only return trips where dogs are known to be allowed"""


class GetTripsRequest(BaseModel):
    origin: Annotated[
        str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]
    r"""The ID of the origin station"""

    destination: Annotated[
        str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
    ]
    r"""The ID of the destination station"""

    date_: Annotated[
        datetime,
        pydantic.Field(alias="date"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ]
    r"""The date and time of the trip in ISO 8601 format in origin station's timezone."""

    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"""

    bicycles: Annotated[
        Optional[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = False
    r"""Only return trips where bicycles are known to be allowed"""

    dogs: Annotated[
        Optional[bool],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = False
    r"""Only return trips where dogs are known to be allowed"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["page", "limit", "bicycles", "dogs"])
        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 GetTripsXMLLinksTypedDict(TypedDict):
    r"""Links to the next and previous pages of a paginated response."""

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


class GetTripsXMLLinks(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 GetTripsXMLResponseBodyTypedDict(TypedDict):
    r"""This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS)."""

    data: NotRequired[List[TripTypedDict]]
    links: NotRequired[GetTripsXMLLinksTypedDict]


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

    data: Optional[List[Trip]] = None

    links: Optional[GetTripsXMLLinks] = 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 DataTypedDict(TypedDict):
    r"""The link to the destination station resource."""

    id: NotRequired[str]
    r"""Unique identifier for the trip"""
    origin: NotRequired[str]
    r"""The starting station of the trip"""
    destination: NotRequired[str]
    r"""The destination station of the trip"""
    departure_time: NotRequired[datetime]
    r"""The date and time when the trip departs"""
    arrival_time: NotRequired[datetime]
    r"""The date and time when the trip arrives"""
    operator: NotRequired[str]
    r"""The name of the operator of the trip"""
    price: NotRequired[float]
    r"""The cost of the trip"""
    bicycles_allowed: NotRequired[bool]
    r"""Indicates whether bicycles are allowed on the trip"""
    dogs_allowed: NotRequired[bool]
    r"""Indicates whether dogs are allowed on the trip"""
    self_: NotRequired[str]


class Data(BaseModel):
    r"""The link to the destination station resource."""

    id: Optional[str] = None
    r"""Unique identifier for the trip"""

    origin: Optional[str] = None
    r"""The starting station of the trip"""

    destination: Optional[str] = None
    r"""The destination station of the trip"""

    departure_time: Optional[datetime] = None
    r"""The date and time when the trip departs"""

    arrival_time: Optional[datetime] = None
    r"""The date and time when the trip arrives"""

    operator: Optional[str] = None
    r"""The name of the operator of the trip"""

    price: Optional[float] = None
    r"""The cost of the trip"""

    bicycles_allowed: Optional[bool] = None
    r"""Indicates whether bicycles are allowed on the trip"""

    dogs_allowed: Optional[bool] = None
    r"""Indicates whether dogs are allowed on the trip"""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "id",
                "origin",
                "destination",
                "departure_time",
                "arrival_time",
                "operator",
                "price",
                "bicycles_allowed",
                "dogs_allowed",
                "self",
            ]
        )
        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 GetTripsLinksTypedDict(TypedDict):
    r"""Links to the next and previous pages of a paginated response."""

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


class GetTripsLinks(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 GetTripsResponseBodyTypedDict(TypedDict):
    r"""This is a generic request/response wrapper which contains both data and links which serve as hypermedia controls (HATEOAS)."""

    data: NotRequired[List[DataTypedDict]]
    links: NotRequired[GetTripsLinksTypedDict]


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

    data: Optional[List[Data]] = None

    links: Optional[GetTripsLinks] = 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


GetTripsResponseResultTypedDict = TypeAliasType(
    "GetTripsResponseResultTypedDict", Union[GetTripsResponseBodyTypedDict, bytes]
)


GetTripsResponseResult = TypeAliasType(
    "GetTripsResponseResult", Union[GetTripsResponseBody, bytes]
)


class GetTripsResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: GetTripsResponseResultTypedDict


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

    result: GetTripsResponseResult


try:
    Data.model_rebuild()
except NameError:
    pass
try:
    GetTripsLinks.model_rebuild()
except NameError:
    pass
