1#[macro_export]
2macro_rules! response {
3 (pub struct $name: ident {$($field: ident: $t: ty $(as $alias: literal)? $(:$venc:vis encoded)? $(; default $vdef:vis)?),* $(,)?}) => {
4 #[derive(Clone, Debug, Deserialize)]
5 pub struct $name {
6 $(
7 #[serde(
8 $(rename = $alias,)?
9 $(deserialize_with = "deserialize_number_from_string"$venc,)?
10 $(default $vdef,)?
11 )]
12 pub $field: $t
13 ),*
14 }
15 };
16}
17
18pub mod departure_monitor;
19pub mod stop_finder;
20
21pub use departure_monitor::*;
22pub use stop_finder::*;
23
24use std::collections::HashMap;
25use serde::Deserialize;
26use serde_aux::prelude::*;
27
28use crate::{ApiVec, request::types::StationId};
29
30response!(pub struct Parameter {
31 name: String,
32 value: String,
33 typ: Option<String> as "type",
34 edit: Option<String>
35});
36
37response!(pub struct ResponseData {
38 input: HashMap<String, String>,
39 points: ApiVec<Point>
40});
41
42response!(pub struct Input {
43 input: String
44});
45
46response!(pub struct Point {
47 usage: String,
48 typ: String as "type",
49 name: String,
50 stateless: String,
51 any_type: Option<String> as "anyType",
52 sort: Option<String>,
53 quality: Option<String>,
54 best: Option<String>,
55 object: Option<String>,
56 main_loc: Option<String> as "mainLoc",
57 modes: Option<String>,
58});
60
61response!(pub struct Station {
62 id: String,
63 gid: String,
64 omc: u32: encoded,
65 place_id: String as "placeID",
66 place: String,
67 coords: Option<String>
68});
69
70response!(pub struct Date {
71 day: String,
72 month: String,
73 year: String,
74 weekday: String
75});
76
77response!(pub struct DateTime {
78 deparr: Option<String>,
79 ttp_from: Option<String> as "ttpFrom",
80 ttp_to: Option<String> as "ttpTo",
81 year: Option<String>,
82 month: Option<String>,
83 day: Option<String>,
84 weekday: Option<String>,
85 hour: Option<String>,
86 minute: Option<String>,
87});
88
89response!(pub struct ServingLines {
90 train_info: String as "trainInfo",
91 selected: usize: encoded,
92 lines: Vec<ServingLineEntry>
93});
94
95response!(pub struct ServingLineEntry {
96 mode: LineMode,
97 index: String
98});
99
100response!(pub struct LineMode {
101 name: String,
102 number: String,
103 product: String,
104 product_id: String as "productId",
105 typ: String as "type",
106 code: String,
107 destination: String,
108 destination_id: String as "destID",
109 desc: String,
110 timetable_period: String as "timetablePeriod",
111 diva: Diva
112});
113
114response!(pub struct Diva {
115 branch: String,
116 line: String,
117 supplement: String,
118 dir: String,
119 project: String,
120 network: String,
121 stateless: String,
122 trip_code: String as "tripCode",
123 operator: String,
124 op_code: String as "opCode",
125 v_from: String as "vF",
126 v_to: String as "vTo",
127 attrs: Vec<Parameter>
128});
129
130response!(pub struct Departure {
131 stop_id: StationId as "stopID": encoded,
132 x: f32: encoded,
133 y: f32: encoded,
134 map_name: String as "mapName",
135 area: String,
136 platform: String,
137 platform_name: String as "platformName",
138 stop_name: String as "stopName",
139 name_wo: String as "nameWO",
140 point_type: Option<String> as "pointType",
141 countdown: String,
142 realtime_status: Option<String> as "realtimeStatus",
143 realtime_trip_status: Option<String> as "realtimeTripStatus",
144 date_time: DateTime as "dateTime",
145 real_date_time: Option<DateTime> as "realDateTime",
146 serving_line: ServingLine as "servingLine",
147 operator: Option<Operator>,
148 stop_infos: Option<ApiVec<Info>> as "stopInfos",
149 line_infos: Option<ApiVec<Info>> as "lineInfos",
150 attrs: Vec<Parameter>; default,
151});
152
153response!(pub struct ServingLine {
154 key: String,
155 code: String,
156 number: String,
157 symbol: String,
158 mot_type: String as "motType",
159 mt_subcode: String as "mtSubcode",
160 realtime: String,
161 direction: String,
162 direction_from: String as "directionFrom",
163 train_name: Option<String> as "trainName",
164 train_number: Option<String> as "trainNum",
165 name: String,
166 delay: Option<String>,
167 dest_id: String as "destID",
168 stateless: String
169});
170
171response!(pub struct Operator {
172 code: String,
173 name: String,
174 public_code: String as "publicCode"
175});
176
177response!(pub struct Info {
178 info_link_text: String as "infoLinkText",
179 info_link_url: String as "infoLinkURL",
180 info_text: InfoText as "infoText",
181 param_list: Vec<Parameter> as "paramList",
182 additional_links: Vec<AdditionalLink> as "additionalLinks"; default,
183});
184
185response!(pub struct InfoText {
186 content: String,
187 subtitle: String,
188 subject: String,
189 additional_text: String as "additionalText",
190 html_text: String as "htmlText",
191 wml_text: String as "wmlText",
192 sms_text: String as "smsText",
193 speech_text: String as "speechText"
194});
195
196response!(pub struct AdditionalLink {
197 id: String as "ID",
198 link_url: String as "linkURL",
199 link_text: String as "linkText",
200 link_text_short: String as "linkTextShort",
201 link_target: String as "linkTarget"
202});
203