use serde::Deserialize;
#[derive(Debug, Clone)]
pub enum StatsType {
LastHour,
LastDay,
LastWeek,
LastMonth,
LastYear,
Custom {
start: String,
end: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TopStatsType {
Clients,
Domains,
BlockedDomains,
}
impl std::fmt::Display for TopStatsType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Clients => write!(f, "TopClients"),
Self::Domains => write!(f, "TopDomains"),
Self::BlockedDomains => write!(f, "TopBlockedDomains"),
}
}
}
impl StatsType {
pub(crate) fn as_str(&self) -> &str {
match self {
Self::LastHour => "LastHour",
Self::LastDay => "LastDay",
Self::LastWeek => "LastWeek",
Self::LastMonth => "LastMonth",
Self::LastYear => "LastYear",
Self::Custom { .. } => "Custom",
}
}
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StatEntry {
#[serde(default)]
pub label: Option<String>,
#[serde(default)]
pub total_queries: u64,
#[serde(default)]
pub total_no_error: u64,
#[serde(default)]
pub total_blocked: u64,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DashboardStats {
#[serde(default)]
pub stats: Option<StatEntry>,
#[serde(flatten)]
pub extra: serde_json::Value,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TopStats {
#[serde(flatten)]
pub data: serde_json::Value,
}