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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! Taxi structs and data structures

pub mod prelude {
    pub use {
        crate::taxi::{
            taxi_avail::TaxiAvailResp,
            taxi_stands::{TaxiStand, TaxiStandsResp},
        },
        crate::utils::Coordinates,
    };
}

pub mod taxi_avail {
    use crate::utils::Coordinates;
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
    pub struct InternalCoordinates {
        /// Original data already float
        #[serde(alias = "Longitude")]
        pub long: f64,

        /// Original data already float
        #[serde(alias = "Latitude")]
        pub lat: f64,
    }

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
    pub struct TaxiAvailResp {
        pub value: Vec<InternalCoordinates>,
    }

    impl From<TaxiAvailResp> for Vec<Coordinates> {
        fn from(data: TaxiAvailResp) -> Self {
            data.value.into_iter().map(|f| f.into()).collect()
        }
    }

    impl From<InternalCoordinates> for Coordinates {
        fn from(data: InternalCoordinates) -> Self {
            Self {
                lat: data.lat,
                long: data.long,
            }
        }
    }
}

pub mod taxi_stands {
    use crate::utils::de::from_str_to_bool;
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Default)]
    pub enum TaxiStandOwner {
        #[serde(rename = "LTA")]
        Lta,

        #[serde(rename = "CCS")]
        Ccs,

        Private,

        #[default]
        #[serde(other)]
        Unknown,
    }

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Default)]
    pub enum TaxiStandType {
        /// Allow taxis to queue in the taxi bays and wait for passengers
        Stand,

        /// Allow taxis to perform immediate pick up and drop off of passengers
        Stop,

        #[default]
        #[serde(other)]
        Unknown,
    }

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
    #[serde(rename_all = "PascalCase")]
    pub struct TaxiStandRaw {
        pub taxi_code: String,

        /// Original data already float
        #[serde(alias = "Latitude")]
        pub lat: f64,

        /// Original data already float
        #[serde(alias = "Longitude")]
        pub long: f64,

        #[serde(alias = "Bfa", deserialize_with = "from_str_to_bool")]
        pub is_barrier_free: bool,

        #[serde(alias = "Ownership")]
        pub owner: TaxiStandOwner,

        #[serde(alias = "Type")]
        pub stand_type: TaxiStandType,
        pub name: String,
    }

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
    pub struct TaxiStand {
        pub taxi_code: String,
        pub lat: f64,
        pub long: f64,
        pub is_barrier_free: bool,
        pub owner: TaxiStandOwner,
        pub stand_type: TaxiStandType,
        pub name: String,
    }

    #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
    pub struct TaxiStandsResp {
        value: Vec<TaxiStandRaw>,
    }

    impl From<TaxiStandRaw> for TaxiStand {

        #[inline(always)]
        fn from(r: TaxiStandRaw) -> Self {
            Self {
                taxi_code: r.taxi_code,
                lat: r.lat,
                long: r.long,
                is_barrier_free: r.is_barrier_free,
                owner: r.owner,
                stand_type: r.stand_type,
                name: r.name
            }
        }
    }

    impl From<TaxiStandsResp> for Vec<TaxiStand> {
        fn from(data: TaxiStandsResp) -> Self {
            data.value.into_iter().map(Into::into).collect()
        }
    }
}