use crate::{Param, ParamError, ParamList};
#[derive(Debug)]
pub enum GetStatsParam<'a> {
Duration(&'a str),
End(&'a str),
Event(&'a str),
Resolution(&'a str),
Start(&'a str),
}
impl<'a> Param for GetStatsParam<'a> {
fn try_as_tuple(&self) -> Result<(String, String), ParamError> {
Ok(match self {
Self::Duration(v) => ("duration".to_string(), v.to_string()),
Self::End(v) => ("end".to_string(), v.to_string()),
Self::Event(v) => ("event".to_string(), v.to_string()),
Self::Resolution(v) => ("resolution".to_string(), v.to_string()),
Self::Start(v) => ("start".to_string(), v.to_string()),
})
}
}
#[derive(Debug)]
pub struct GetStatsParamList<'a> {
pub values: Vec<GetStatsParam<'a>>,
}
impl<'a> Default for GetStatsParamList<'a> {
fn default() -> Self {
Self {
values: vec![
GetStatsParam::Event("accepted"),
GetStatsParam::Event("delivered"),
GetStatsParam::Event("failed"),
],
}
}
}
impl<'a> ParamList for GetStatsParamList<'a> {
type ParamType = GetStatsParam<'a>;
fn add(mut self, param: Self::ParamType) -> Self {
self.values.push(param);
self
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct GetStatsResponse {
end: String,
resolution: String,
start: String,
stats: Vec<StatItem>,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct StatItem {
time: String,
accepted: StatAccepted,
delivered: StatDelivered,
failed: StatFailed,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct StatAccepted {
outgoing: i64,
incoming: i64,
total: i64,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct StatDelivered {
smtp: i64,
http: i64,
total: i64,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct StatFailed {
permanent: StatFailedPermanent,
temporary: StatFailedTemporary,
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct StatFailedPermanent {
bounce: i64,
delayed_bounce: i64,
suppress_bounce: i64,
suppress_unsubscribe: i64,
suppress_complaint: i64,
total: i64,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct StatFailedTemporary {
espblock: i64,
}