made_core/value_objects/ceremony/
role_action.rs1use serde::{Deserialize, Serialize};
2
3use super::{StepId, TransitionTrigger};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
6#[serde(tag = "kind", content = "value", rename_all = "snake_case")]
7pub enum RoleAction {
8 Step(StepId),
9 Transition(TransitionTrigger),
10 RequestIntervention,
11 RespondToIntervention,
12}
13
14impl RoleAction {
15 #[must_use]
16 pub fn step(step_id: StepId) -> Self {
17 Self::Step(step_id)
18 }
19
20 #[must_use]
21 pub fn transition(trigger: TransitionTrigger) -> Self {
22 Self::Transition(trigger)
23 }
24
25 #[must_use]
26 pub const fn request_intervention() -> Self {
27 Self::RequestIntervention
28 }
29
30 #[must_use]
31 pub const fn respond_to_intervention() -> Self {
32 Self::RespondToIntervention
33 }
34
35 #[must_use]
36 pub fn from_capability_label(label: &str) -> Option<Self> {
37 match label {
38 "request_intervention" => Some(Self::RequestIntervention),
39 "respond_to_intervention" => Some(Self::RespondToIntervention),
40 _ => None,
41 }
42 }
43
44 #[must_use]
45 pub fn step_id(&self) -> Option<&StepId> {
46 match self {
47 Self::Step(step_id) => Some(step_id),
48 Self::Transition(_) | Self::RequestIntervention | Self::RespondToIntervention => None,
49 }
50 }
51
52 #[must_use]
53 pub fn transition_trigger(&self) -> Option<&TransitionTrigger> {
54 match self {
55 Self::Step(_) | Self::RequestIntervention | Self::RespondToIntervention => None,
56 Self::Transition(trigger) => Some(trigger),
57 }
58 }
59}