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

from __future__ import annotations
from datetime import datetime
from pydantic import model_serializer
from train_travel.types import BaseModel, UNSET_SENTINEL
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class TripTypedDict(TypedDict):
    r"""A train trip."""

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


class Trip(BaseModel):
    r"""A train trip."""

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

    @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",
            ]
        )
        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
