strecken_info/request/
filter.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use chrono::NaiveDateTime;
use serde::Serialize;

use super::time;

const REGION_AREA_ALL: &[RegionArea] = &[
    RegionArea::Middle,
    RegionArea::North,
    RegionArea::East,
    RegionArea::South,
    RegionArea::SouthEast,
    RegionArea::SouthWest,
    RegionArea::West,
];

#[derive(Clone, Serialize)]
pub struct DisruptionsFilter {
    #[serde(rename = "baustellenAktiv")]
    pub construction_sites: bool,
    #[serde(rename = "baustellenNurTotalsperrung")]
    pub construction_sites_only_full_closures: bool,
    #[serde(rename = "betriebsstellen")]
    pub stations: Vec<String>,
    #[serde(rename = "regionalbereiche")]
    pub region_areas: Vec<RegionArea>,
    #[serde(rename = "stoerungenAktiv")]
    pub disruptions: bool,
    #[serde(rename = "streckennummern")]
    pub railway_line_numbers: Vec<u32>,
    #[serde(rename = "streckenruhenAktiv")]
    pub railway_line_rest: bool,
    #[serde(rename = "wirkungsdauer")]
    pub duration_of_effect: u32,
    #[serde(rename = "zeitraum")]
    pub time: DisruptionsFilterTime,
}

impl Default for DisruptionsFilter {
    fn default() -> Self {
        Self {
            construction_sites: true,
            construction_sites_only_full_closures: false,
            stations: Vec::new(),
            region_areas: Vec::from(REGION_AREA_ALL),
            disruptions: true,
            railway_line_numbers: Vec::new(),
            railway_line_rest: true,
            duration_of_effect: 0,
            time: DisruptionsFilterTime::Hours { hours: 2 },
        }
    }
}

#[derive(Clone, Serialize)]
pub enum RegionArea {
    #[serde(rename = "MITTE")]
    Middle,
    #[serde(rename = "NORD")]
    North,
    #[serde(rename = "OST")]
    East,
    #[serde(rename = "SUED")]
    South,
    #[serde(rename = "SUEDOST")]
    SouthEast,
    #[serde(rename = "SUEDWEST")]
    SouthWest,
    #[serde(rename = "WEST")]
    West,
}

#[derive(Clone, Serialize)]
pub enum DisruptionsFilterTimeWeekday {
    #[serde(rename = "MONTAG")]
    Monday,
    #[serde(rename = "DIENSTAG")]
    Tuesday,
    #[serde(rename = "MITTWOCH")]
    Wednesday,
    #[serde(rename = "DONNERSTAG")]
    Thursday,
    #[serde(rename = "FREITAG")]
    Friday,
    #[serde(rename = "SAMSTAG")]
    Saturday,
    #[serde(rename = "SONNTAG")]
    Sunday,
}

#[derive(Clone, Serialize)]
#[serde(tag = "type")]
pub enum DisruptionsFilterTime {
    #[serde(rename = "ROLLIEREND")]
    Hours {
        #[serde(rename = "stunden")]
        hours: u32,
    },
    #[serde(rename = "FIX")]
    Fix {
        #[serde(rename = "beginn", serialize_with = "time::serialize_datetime")]
        start: NaiveDateTime,
        #[serde(rename = "ende", serialize_with = "time::serialize_datetime")]
        end: NaiveDateTime,
        #[serde(rename = "wochentage")]
        weekdays: Vec<DisruptionsFilterTimeWeekday>,
    },
}