1use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::{DvbResponse, common::Mot, error::Result, time::DvbTime};
7
8const ROUTE_CHANGES_URL: &str = "https://webapi.vvo-online.de/rc";
9const ROUTE_CHANGE_LINES_URL: &str = "https://webapi.vvo-online.de/rc/lines";
10
11#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
12#[serde(rename_all = "PascalCase")]
13pub struct ValidityPeriod {
14 pub begin: Option<DvbTime>,
15 pub end: Option<DvbTime>,
16}
17
18#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
19#[serde(rename_all = "PascalCase")]
20pub struct Change {
21 pub id: Option<String>,
22 pub title: Option<String>,
23 pub description: Option<String>,
24 pub r#type: Option<String>,
25 pub trip_request_include: Option<bool>,
26 pub publish_date: Option<DvbTime>,
27 #[serde(default)]
28 pub line_ids: Vec<String>,
29 #[serde(default)]
30 pub validity_periods: Vec<ValidityPeriod>,
31}
32
33#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
34#[serde(rename_all = "PascalCase")]
35pub struct Banner {
36 pub title: Option<String>,
37 pub description: Option<String>,
38 pub r#type: Option<String>,
39 pub modified_time: Option<DvbTime>,
40 pub trip_request_include: Option<bool>,
41}
42
43#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
44#[serde(rename_all = "PascalCase")]
45pub struct Diva {
46 pub number: Option<String>,
47 pub network: Option<String>,
48}
49
50#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
51#[serde(rename_all = "PascalCase")]
52pub struct Line {
53 pub id: Option<String>,
54 pub name: Option<String>,
55 pub mot: Option<Mot>,
56 pub transportation_company: Option<String>,
57 #[serde(default)]
58 pub divas: Vec<Diva>,
59}
60
61#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
62#[serde(rename_all = "PascalCase")]
63pub struct RouteChanges {
64 #[serde(default)]
65 pub changes: Vec<Change>,
66 #[serde(default)]
67 pub banners: Vec<Banner>,
68 #[serde(default)]
69 pub lines: Vec<Line>,
70}
71
72#[derive(Serialize, Deserialize, JsonSchema, Clone, Debug)]
73#[serde(rename_all = "PascalCase")]
74pub struct RouteChangeLines {
75 #[serde(default)]
76 pub lines: Vec<Line>,
77}
78
79#[derive(Serialize, Clone, Debug, Default)]
80pub struct Params<'a> {
81 pub shortterm: Option<bool>,
83 pub provider: Option<&'a str>,
85 pub format: Option<&'a str>,
87}
88
89#[derive(Serialize, Clone, Debug, Default)]
90pub struct LinesParams<'a> {
91 pub provider: Option<&'a str>,
93 pub format: Option<&'a str>,
95}
96
97pub async fn route_changes(params: Params<'_>) -> Result<DvbResponse<RouteChanges>> {
107 let response = reqwest::Client::new()
108 .post(ROUTE_CHANGES_URL)
109 .json(¶ms)
110 .send()
111 .await?
112 .json()
113 .await?;
114
115 Ok(response)
116}
117
118pub async fn route_change_lines(params: LinesParams<'_>) -> Result<DvbResponse<RouteChangeLines>> {
128 let response = reqwest::Client::new()
129 .post(ROUTE_CHANGE_LINES_URL)
130 .json(¶ms)
131 .send()
132 .await?
133 .json()
134 .await?;
135
136 Ok(response)
137}