use std::borrow::Cow;
use crate::query::AsApiStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum FloodModel {
GlofasV4Seamless,
GlofasV4Forecast,
GlofasV4Consolidated,
GlofasV3Seamless,
GlofasV3Forecast,
GlofasV3Consolidated,
Other(Cow<'static, str>),
}
impl FloodModel {
pub fn other(token: impl Into<Cow<'static, str>>) -> Self {
Self::Other(token.into())
}
}
impl AsApiStr for FloodModel {
fn as_api_str(&self) -> Cow<'static, str> {
match self {
Self::GlofasV4Seamless => Cow::Borrowed("seamless_v4"),
Self::GlofasV4Forecast => Cow::Borrowed("forecast_v4"),
Self::GlofasV4Consolidated => Cow::Borrowed("consolidated_v4"),
Self::GlofasV3Seamless => Cow::Borrowed("seamless_v3"),
Self::GlofasV3Forecast => Cow::Borrowed("forecast_v3"),
Self::GlofasV3Consolidated => Cow::Borrowed("consolidated_v3"),
Self::Other(token) => token.clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum FloodDailyVar {
RiverDischarge,
RiverDischargeMean,
RiverDischargeMedian,
RiverDischargeMax,
RiverDischargeMin,
RiverDischargeP25,
RiverDischargeP75,
Other(Cow<'static, str>),
}
impl FloodDailyVar {
pub fn other(token: impl Into<Cow<'static, str>>) -> Self {
Self::Other(token.into())
}
}
impl AsApiStr for FloodDailyVar {
fn as_api_str(&self) -> Cow<'static, str> {
match self {
Self::RiverDischarge => Cow::Borrowed("river_discharge"),
Self::RiverDischargeMean => Cow::Borrowed("river_discharge_mean"),
Self::RiverDischargeMedian => Cow::Borrowed("river_discharge_median"),
Self::RiverDischargeMax => Cow::Borrowed("river_discharge_max"),
Self::RiverDischargeMin => Cow::Borrowed("river_discharge_min"),
Self::RiverDischargeP25 => Cow::Borrowed("river_discharge_p25"),
Self::RiverDischargeP75 => Cow::Borrowed("river_discharge_p75"),
Self::Other(token) => token.clone(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn flood_model_tokens_are_formatted() {
assert_eq!(FloodModel::GlofasV4Seamless.as_api_str(), "seamless_v4");
assert_eq!(FloodModel::GlofasV4Forecast.as_api_str(), "forecast_v4");
assert_eq!(
FloodModel::GlofasV4Consolidated.as_api_str(),
"consolidated_v4"
);
assert_eq!(FloodModel::GlofasV3Seamless.as_api_str(), "seamless_v3");
assert_eq!(FloodModel::GlofasV3Forecast.as_api_str(), "forecast_v3");
assert_eq!(
FloodModel::GlofasV3Consolidated.as_api_str(),
"consolidated_v3"
);
assert_eq!(
FloodModel::other("custom_flood_model").as_api_str(),
"custom_flood_model"
);
}
#[test]
fn flood_daily_tokens_are_formatted() {
assert_eq!(
FloodDailyVar::RiverDischarge.as_api_str(),
"river_discharge"
);
assert_eq!(
FloodDailyVar::RiverDischargeMean.as_api_str(),
"river_discharge_mean"
);
assert_eq!(
FloodDailyVar::RiverDischargeP75.as_api_str(),
"river_discharge_p75"
);
assert_eq!(
FloodDailyVar::other("custom_flood_var").as_api_str(),
"custom_flood_var"
);
}
}