use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
pub mod dependency;
pub mod host;
pub mod notification;
pub mod service;
pub mod user;
pub mod zone;
pub trait IcingaJoinType {}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum IcingaJoins<'a, JT>
where
JT: IcingaJoinType + Ord + std::fmt::Display,
{
NoJoins,
SpecificJoins {
full: Vec<JT>,
partial: BTreeMap<JT, Vec<&'a str>>,
},
AllJoins,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum IcingaJoinResult<T> {
Full(T),
Partial(BTreeMap<String, serde_json::Value>),
}
pub(crate) fn add_joins_to_url<JT: IcingaJoinType + Ord + std::fmt::Display>(
url: &mut url::Url,
joins: &IcingaJoins<JT>,
) -> Result<(), crate::error::Error> {
match joins {
IcingaJoins::NoJoins => (),
IcingaJoins::AllJoins => {
url.query_pairs_mut().append_pair("all_joins", "1");
}
IcingaJoins::SpecificJoins { full, partial } => {
for j in full {
url.query_pairs_mut().append_pair("joins", &j.to_string());
}
for (j, fields) in partial {
for f in fields {
url.query_pairs_mut()
.append_pair("joins", &format!("{}.{}", &j.to_string(), &f));
}
}
}
}
Ok(())
}