made_core/value_objects/delivery/
attention_kind.rs1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
11#[serde(rename_all = "snake_case")]
12pub enum AttentionKind {
13 ResultAvailable,
15 ReviewRejected,
17 StepFailed,
19 Blocked,
21 HumanDecisionRequested,
23 DeadlineExceeded,
25 InactivityDetected,
27 InterventionRequested,
29 CeremonyEnded,
31}
32
33impl AttentionKind {
34 pub const ALL: [Self; 9] = [
36 Self::ResultAvailable,
37 Self::ReviewRejected,
38 Self::StepFailed,
39 Self::Blocked,
40 Self::HumanDecisionRequested,
41 Self::DeadlineExceeded,
42 Self::InactivityDetected,
43 Self::InterventionRequested,
44 Self::CeremonyEnded,
45 ];
46
47 #[must_use]
55 pub fn from_label(label: &str) -> Option<Self> {
56 Self::ALL.into_iter().find(|kind| kind.as_str() == label)
57 }
58
59 #[must_use]
60 pub const fn as_str(self) -> &'static str {
61 match self {
62 Self::ResultAvailable => "result_available",
63 Self::ReviewRejected => "review_rejected",
64 Self::StepFailed => "step_failed",
65 Self::Blocked => "blocked",
66 Self::HumanDecisionRequested => "human_decision_requested",
67 Self::DeadlineExceeded => "deadline_exceeded",
68 Self::InactivityDetected => "inactivity_detected",
69 Self::InterventionRequested => "intervention_requested",
70 Self::CeremonyEnded => "ceremony_ended",
71 }
72 }
73
74 #[must_use]
80 pub const fn is_blocking(self) -> bool {
81 matches!(
82 self,
83 Self::Blocked
84 | Self::HumanDecisionRequested
85 | Self::CeremonyEnded
86 | Self::DeadlineExceeded
87 | Self::InterventionRequested
88 )
89 }
90}
91
92impl fmt::Display for AttentionKind {
93 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
94 formatter.write_str(self.as_str())
95 }
96}
97
98#[cfg(test)]
99mod tests {
100 use super::*;
101
102 #[test]
103 fn every_kind_is_listed_once_and_serialises_as_its_name() {
104 let mut seen = std::collections::BTreeSet::new();
105 for kind in AttentionKind::ALL {
106 assert!(seen.insert(kind), "{kind} is listed twice");
107 assert_eq!(
108 serde_json::to_string(&kind).unwrap(),
109 format!("\"{}\"", kind.as_str())
110 );
111 }
112 assert_eq!(seen.len(), 9);
113 }
114
115 #[test]
116 fn results_and_inactivity_are_the_droppable_kinds() {
117 assert!(!AttentionKind::ResultAvailable.is_blocking());
118 assert!(!AttentionKind::InactivityDetected.is_blocking());
119 assert!(AttentionKind::HumanDecisionRequested.is_blocking());
120 }
121}