use crate::lta_client::LTAClient;
use crate::utils::commons::{build_req, Result};
pub mod passenger_vol {
use serde::{Deserialize, Serialize};
pub const URL_BY_BUS_STOPS: &str = "http://datamall2.mytransport.sg/ltaodataservice/PV/Bus";
pub const URL_BY_OD_BUS_STOPS: &str =
"http://datamall2.mytransport.sg/ltaodataservice/PV/ODBus";
pub const URL_BY_TRAIN: &str = "http://datamall2.mytransport.sg/ltaodataservice/PV/Train";
pub const URL_BY_OD_TRAIN: &str = "http://datamall2.mytransport.sg/ltaodataservice/PV/ODTrain";
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum VolType {
BusStops,
OdBusStop,
Train,
OdTrain,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct Link {
#[serde(rename = "Link")]
pub link: String,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct PassengerVolRawResp {
pub value: Vec<Link>,
}
}
pub fn get_passenger_vol_by(
client: <AClient,
vol_type: passenger_vol::VolType,
) -> Result<Vec<String>> {
use crate::crowd::passenger_vol::VolType;
let url = match vol_type {
VolType::BusStops => passenger_vol::URL_BY_BUS_STOPS,
VolType::OdBusStop => passenger_vol::URL_BY_OD_BUS_STOPS,
VolType::Train => passenger_vol::URL_BY_TRAIN,
VolType::OdTrain => passenger_vol::URL_BY_OD_TRAIN,
};
let resp: passenger_vol::PassengerVolRawResp = build_req(client, url)?;
let as_str = resp.value.into_iter().map(|f| f.link).collect();
Ok(as_str)
}