use serde::{Deserialize, Serialize};
use crate::partition::PartitionId;
use crate::stores::StoreUse;
use crate::wake::Wake;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct KernelInventory {
pub app_name: String,
pub targets: Vec<String>,
pub triggers: Vec<InventoryTrigger>,
pub wake_sources: Vec<String>,
pub schedules: bool,
pub signal_partitions: Vec<PartitionId>,
pub stores: Vec<StoreUse>,
pub warnings: Vec<InventoryWarning>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct InventoryTrigger {
pub name: String,
pub wake: Wake,
pub target: String,
pub queue: String,
pub partition: PartitionId,
#[serde(default)]
pub overlap: crate::wake::WakeOverlap,
pub served: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct InventoryWarning {
pub code: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subject: Option<String>,
pub message: String,
}
impl InventoryWarning {
pub const TRIGGER_UNSERVED: &'static str = "kernel.trigger.unserved";
pub const SIGNAL_UNFILED: &'static str = "kernel.trigger.signal_unfiled";
pub const STORE_IN_MEMORY: &'static str = "kernel.store.in_memory";
pub const KERNEL_IDLE: &'static str = "kernel.idle";
pub const APPROVALS_UNROUTED: &'static str = "kernel.approvals.unrouted";
pub const APPROVALS_UNHEARD: &'static str = "kernel.approvals.unheard";
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
Self { code: code.into(), subject: None, message: message.into() }
}
#[must_use]
pub fn with_subject(mut self, subject: impl Into<String>) -> Self {
self.subject = Some(subject.into());
self
}
}