use serde::Deserialize;
use crate::serde_helpers::from_str_to_f64;
#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "PascalCase")]
pub enum Service {
Forum,
Website,
#[serde(rename = "AUR")]
Aur,
Wiki
}
#[derive(Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Status {
Success,
Warning,
Error,
#[serde(other)]
Unknown
}
#[derive(Debug, Deserialize)]
pub struct MonitorListResponse {
status: String,
psp: Psp,
days: Vec<String>,
statistics: Statistics,
}
#[derive(Debug, Deserialize)]
pub struct Psp {
#[serde(rename = "perPage")]
per_page: u32,
#[serde(rename = "totalMonitors")]
total_monitors: u32,
monitors: Vec<Monitor>,
}
#[derive(Debug, Deserialize)]
pub struct Monitor {
#[serde(rename = "monitorId")]
monitor_id: u64,
#[serde(rename = "createdAt")]
created_at: u64,
#[serde(rename = "statusClass")]
status_class: Status,
name: Service,
url: Option<String>,
#[serde(rename = "type")]
type_: String,
#[serde(rename = "groupId")]
group_id: u32,
#[serde(rename = "groupName")]
group_name: String,
#[serde(rename = "dailyRatios")]
daily_ratios: Vec<DailyRatio>,
#[serde(rename = "90dRatio")]
d90_ratio: Option<Ratio>,
#[serde(rename = "30dRatio")]
d30_ratio: Option<Ratio>,
#[serde(rename = "hasIncidentComments")]
has_incident_comments: bool,
}
#[derive(Debug, Deserialize)]
pub struct DailyRatio {
#[serde(deserialize_with = "from_str_to_f64")]
ratio: f64,
label: Status,
}
#[derive(Debug, Deserialize)]
pub struct Ratio {
#[serde(deserialize_with = "from_str_to_f64")]
ratio: f64,
label: Status,
}
#[derive(Debug, Deserialize)]
pub struct Statistics {
uptime: Option<String>,
latest_downtime: Option<String>,
counts: Counts,
count_result: String,
}
#[derive(Debug, Deserialize)]
pub struct Counts {
up: u32,
down: u32,
paused: u32,
}
impl MonitorListResponse {
pub fn status(&self) -> &str {
&self.status
}
pub fn psp(&self) -> &Psp {
&self.psp
}
pub fn days(&self) -> &[String] {
&self.days
}
pub fn statistics(&self) -> &Statistics {
&self.statistics
}
}
impl Psp {
pub fn per_page(&self) -> u32 {
self.per_page
}
pub fn total_monitors(&self) -> u32 {
self.total_monitors
}
pub fn monitors(&self) -> &[Monitor] {
&self.monitors
}
}
impl Monitor {
pub fn monitor_id(&self) -> u64 {
self.monitor_id
}
pub fn created_at(&self) -> u64 {
self.created_at
}
pub fn status_class(&self) -> &Status {
&self.status_class
}
pub fn name(&self) -> &Service {
&self.name
}
pub fn url(&self) -> Option<&String> {
self.url.as_ref()
}
pub fn type_(&self) -> &str {
&self.type_
}
pub fn group_id(&self) -> u32 {
self.group_id
}
pub fn group_name(&self) -> &str {
&self.group_name
}
pub fn daily_ratios(&self) -> &[DailyRatio] {
&self.daily_ratios
}
pub fn d90_ratio(&self) -> Option<&Ratio> {
self.d90_ratio.as_ref()
}
pub fn d30_ratio(&self) -> Option<&Ratio> {
self.d30_ratio.as_ref()
}
pub fn has_incident_comments(&self) -> bool {
self.has_incident_comments
}
}
impl DailyRatio {
pub fn ratio(&self) -> f64 {
self.ratio
}
pub fn label(&self) -> &Status {
&self.label
}
}
impl Ratio {
pub fn ratio(&self) -> f64 {
self.ratio
}
pub fn label(&self) -> &Status {
&self.label
}
}
impl Statistics {
pub fn uptime(&self) -> Option<&String> {
self.uptime.as_ref()
}
pub fn latest_downtime(&self) -> Option<&String> {
self.latest_downtime.as_ref()
}
pub fn counts(&self) -> &Counts {
&self.counts
}
pub fn count_result(&self) -> &str {
&self.count_result
}
}
impl Counts {
pub fn up(&self) -> u32 {
self.up
}
pub fn down(&self) -> u32 {
self.down
}
pub fn paused(&self) -> u32 {
self.paused
}
}