use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[non_exhaustive]
pub struct ConfigStateResponse {
pub coordinator_state: String,
pub degraded: Option<DegradedInfoView>,
pub file: FileStateView,
pub last_reload: Option<LastReloadView>,
pub sections: serde_json::Value,
pub recent_events: Vec<serde_json::Value>,
}
impl ConfigStateResponse {
#[must_use]
pub fn new(
coordinator_state: String,
degraded: Option<DegradedInfoView>,
file: FileStateView,
last_reload: Option<LastReloadView>,
sections: serde_json::Value,
recent_events: Vec<serde_json::Value>,
) -> Self {
Self {
coordinator_state,
degraded,
file,
last_reload,
sections,
recent_events,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[non_exhaustive]
pub struct FileStateView {
pub path: String,
pub digest: String,
#[serde(with = "time::serde::rfc3339")]
#[cfg_attr(
feature = "openapi",
schema(value_type = String, format = DateTime)
)]
pub loaded_at: OffsetDateTime,
pub pending_digest: Option<String>,
#[serde(with = "time::serde::rfc3339::option")]
#[cfg_attr(
feature = "openapi",
schema(value_type = Option<String>, format = DateTime)
)]
pub pending_detected_at: Option<OffsetDateTime>,
}
impl FileStateView {
#[must_use]
pub fn new(
path: String,
digest: String,
loaded_at: OffsetDateTime,
pending_digest: Option<String>,
pending_detected_at: Option<OffsetDateTime>,
) -> Self {
Self {
path,
digest,
loaded_at,
pending_digest,
pending_detected_at,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[non_exhaustive]
pub struct LastReloadView {
#[serde(with = "time::serde::rfc3339")]
#[cfg_attr(
feature = "openapi",
schema(value_type = String, format = DateTime)
)]
pub completed_at: OffsetDateTime,
pub sections: Vec<String>,
pub per_subsystem_ms: BTreeMap<String, u64>,
}
impl LastReloadView {
#[must_use]
pub fn new(
completed_at: OffsetDateTime,
sections: Vec<String>,
per_subsystem_ms: BTreeMap<String, u64>,
) -> Self {
Self {
completed_at,
sections,
per_subsystem_ms,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[non_exhaustive]
pub struct DegradedInfoView {
#[serde(with = "time::serde::rfc3339")]
#[cfg_attr(
feature = "openapi",
schema(value_type = String, format = DateTime)
)]
pub since: OffsetDateTime,
pub failed_subsystems: Vec<String>,
pub reason: String,
}
impl DegradedInfoView {
#[must_use]
pub fn new(since: OffsetDateTime, failed_subsystems: Vec<String>, reason: String) -> Self {
Self {
since,
failed_subsystems,
reason,
}
}
}