use std::fmt::{Display, Formatter};
use std::str::FromStr;
use uuid::Uuid;
use crate::budget::BudgetDimension;
use crate::ids::TaskId;
use crate::run::state::RunState;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SubscriptionId(Uuid);
impl SubscriptionId {
pub fn new() -> Self {
SubscriptionId(Uuid::new_v4())
}
pub fn from_uuid(uuid: Uuid) -> Self {
SubscriptionId(uuid)
}
pub fn as_uuid(&self) -> &Uuid {
&self.0
}
}
impl Default for SubscriptionId {
fn default() -> Self {
Self::new()
}
}
impl FromStr for SubscriptionId {
type Err = uuid::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Uuid::from_str(s).map(SubscriptionId)
}
}
impl Display for SubscriptionId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EventFilter {
TaskCompleted {
task_id: TaskId,
},
RunStateChanged {
task_id: TaskId,
state: RunState,
},
BudgetThreshold {
task_id: TaskId,
dimension: BudgetDimension,
threshold_pct: u8,
},
Custom {
key: String,
},
}