use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SubscribeInput {
pub event_types: Vec<String>,
pub clusters: Vec<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NotificationQueryInput {
pub limit: Option<usize>,
pub unread_only: bool,
pub min_priority: Option<u8>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct NotificationSignal {
pub signal_type: String,
pub source_cluster: String,
pub event_type: String,
pub payload: String,
pub priority: u8,
}
pub const MAX_NOTIFICATIONS_PER_AGENT: usize = 500;
pub const MAX_SUBSCRIPTIONS_PER_AGENT: usize = 50;
pub const DEFAULT_NOTIFICATION_LIMIT: usize = 50;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn subscribe_input_serde_roundtrip() {
let input = SubscribeInput {
event_types: vec!["disaster_declared".into()],
clusters: vec!["civic".into()],
};
let json = serde_json::to_string(&input).unwrap();
let decoded: SubscribeInput = serde_json::from_str(&json).unwrap();
assert_eq!(decoded.event_types, input.event_types);
assert_eq!(decoded.clusters, input.clusters);
}
#[test]
fn notification_query_defaults() {
let input = NotificationQueryInput {
limit: None,
unread_only: false,
min_priority: None,
};
assert_eq!(input.limit.unwrap_or(DEFAULT_NOTIFICATION_LIMIT), 50);
}
#[test]
fn notification_signal_serde_roundtrip() {
let signal = NotificationSignal {
signal_type: "notification".into(),
source_cluster: "commons".into(),
event_type: "property_transfer".into(),
payload: r#"{"hash":"abc"}"#.into(),
priority: 2,
};
let json = serde_json::to_string(&signal).unwrap();
let decoded: NotificationSignal = serde_json::from_str(&json).unwrap();
assert_eq!(decoded.source_cluster, "commons");
assert_eq!(decoded.priority, 2);
}
}