use std::fmt::Debug;
use std::fmt::Display;
use strum::AsRefStr;
use strum::Display as StrumDisplay;
use strum::IntoStaticStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, StrumDisplay, AsRefStr, IntoStaticStr)]
pub enum EventType {
Normal,
Warning,
}
pub trait Reason: Debug + Display + AsRef<str> + Clone + Send + Sync + 'static {}
#[derive(Debug)]
pub struct EventData<R: Reason> {
pub type_: EventType,
pub reason: R,
pub message: String,
pub action: Option<String>,
}
impl<R: Reason> EventData<R> {
pub fn normal(reason: R, message: impl Into<String>) -> Self {
Self {
type_: EventType::Normal,
reason,
message: message.into(),
action: None,
}
}
pub fn warning(reason: R, message: impl Into<String>) -> Self {
Self {
type_: EventType::Warning,
reason,
message: message.into(),
action: None,
}
}
pub fn with_action(mut self, action: impl Into<String>) -> Self {
self.action = Some(action.into());
self
}
}