dvb 0.8.0

An unofficial crate to query publicly accessible API methods for Dresden's public transport system.
Documentation
//! Types and functions for querying trip details and stops.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{DvbResponse, common::ArrivalState, error::Result, time::DvbTime};

#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct Platform {
    name: String,
    r#type: String, // enum PlatformType {Platform}
}

#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
#[serde(rename_all = "PascalCase")]
#[non_exhaustive]
pub enum Position {
    Previous,
    Current,
    Next,
    Onward,
}

#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct Stop {
    pub id: String,
    pub name: String,
    pub place: String,
    pub platform: Platform,
    pub latitude: i64,
    pub longitude: i64,
    pub position: Position,
    pub scheduled_time: Option<bool>,
    pub time: DvbTime,
    pub real_time: Option<DvbTime>,
    pub state: Option<ArrivalState>,
    pub occupancy: Option<String>,
}

#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct Trip {
    #[serde(default)]
    pub stops: Vec<Stop>,
}

const TRIP_URL: &str = "https://webapi.vvo-online.de/dm/trip";

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct Params<'a> {
    /// The trip ID to query.
    pub tripid: &'a str,
    /// The time for which to fetch trip details (DvbTime).
    pub time: DvbTime,
    /// The stop ID associated with the trip.
    pub stopid: &'a str,
    /// Whether to include map data.
    pub mapdata: Option<bool>,
}

/// Fetches detailed information for a specific trip from the VVO WebAPI.
///
/// # Arguments
/// * `params` - Parameters including trip ID, time, stop ID, and optional map data.
///
/// # Returns
/// * `Result<DvbResponse<Trip>>` - The parsed response containing trip details.
///
/// Endpoint: `https://webapi.vvo-online.de/dm/trip`
pub async fn trip_details<'a>(params: &Params<'a>) -> Result<DvbResponse<Trip>> {
    let response = reqwest::Client::new()
        .post(TRIP_URL)
        .json(&params)
        .send()
        .await?
        .json()
        .await?;

    Ok(response)
}