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
use crate::types::RegionalRailStop;

pub trait Request {
    fn into_params(self) -> Vec<(&'static str, String)>;
}

#[derive(Debug)]
pub enum Direction {
    North,
    South,
}

impl ToString for Direction {
    fn to_string(&self) -> String {
        match *self {
            Self::North => "N".to_string(),
            Self::South => "S".to_string(),
        }
    }
}

pub struct ArrivalsRequest {
    pub station: RegionalRailStop,
    pub results: Option<u8>,
    pub direction: Option<Direction>,
}

impl Request for ArrivalsRequest {
    fn into_params(self) -> Vec<(&'static str, String)> {
        let mut params = Vec::new();

        params.push(("station", self.station.to_string()));

        if let Some(direction) = self.direction {
            params.push(("direction", direction.to_string()));
        }

        if let Some(results) = self.results {
            params.push(("results", results.to_string()));
        }

        params
    }
}

pub struct NextToArriveRequest {
    pub starting_station: RegionalRailStop,
    pub ending_station: RegionalRailStop,
    pub results: Option<u8>,
}

impl Request for NextToArriveRequest {
    fn into_params(self) -> Vec<(&'static str, String)> {
        let mut params = Vec::new();

        params.push(("req1", self.starting_station.to_string()));
        params.push(("req2", self.ending_station.to_string()));

        if let Some(results) = self.results {
            params.push(("req3", results.to_string()));
        }

        params
    }
}