use std::collections::BTreeMap;
use crate::util::QueryBuilder;
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
pub struct MetricBucket {
pub timestamp: String,
pub count: i64,
}
#[derive(Clone, Debug, Deserialize)]
pub struct UsagePoint {
pub timestamp: String,
pub value: i64,
}
pub type MetricsEvents = BTreeMap<String, Vec<MetricBucket>>;
pub type MetricsUsage = BTreeMap<String, Vec<UsagePoint>>;
#[derive(Clone, Debug, Default)]
pub struct MetricsQuery {
pub types: Vec<String>,
pub start: Option<String>,
pub end: Option<String>,
pub period: Option<u32>,
pub limit: Option<u32>,
pub descending: Option<bool>,
}
impl MetricsQuery {
pub(crate) fn query(&self, types_key: &'static str) -> Vec<(&'static str, String)> {
QueryBuilder::new()
.many(types_key, &self.types)
.opt("start", self.start.as_ref())
.opt("end", self.end.as_ref())
.opt("period", self.period.as_ref())
.opt("limit", self.limit.as_ref())
.opt("descending", self.descending.as_ref())
.build()
}
}