Skip to main content

made_core/value_objects/ceremony/
ceremony_step.rs

1use serde::{Deserialize, Serialize};
2
3use super::{
4    ContextWrites, DynamicRoleBinding, RetryPolicy, StateId, StepHandlerConfig, StepHandlerKind,
5    StepId, StepRepeatPolicy, StepTimeout,
6};
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9pub struct CeremonyStep {
10    id: StepId,
11    state_id: StateId,
12    handler_kind: StepHandlerKind,
13    handler_config: StepHandlerConfig,
14    retry_policy: RetryPolicy,
15    timeout: Option<StepTimeout>,
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    repeat_policy: Option<StepRepeatPolicy>,
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    dynamic_role_binding: Option<DynamicRoleBinding>,
20    #[serde(default, skip_serializing_if = "ContextWrites::is_empty")]
21    context_writes: ContextWrites,
22}
23
24impl CeremonyStep {
25    #[must_use]
26    pub fn new(
27        id: StepId,
28        state_id: StateId,
29        handler_kind: StepHandlerKind,
30        handler_config: StepHandlerConfig,
31        retry_policy: RetryPolicy,
32        timeout: Option<StepTimeout>,
33    ) -> Self {
34        Self {
35            id,
36            state_id,
37            handler_kind,
38            handler_config,
39            retry_policy,
40            timeout,
41            repeat_policy: None,
42            dynamic_role_binding: None,
43            context_writes: ContextWrites::default(),
44        }
45    }
46
47    #[must_use]
48    pub fn with_dynamic_role_binding(mut self, binding: DynamicRoleBinding) -> Self {
49        self.dynamic_role_binding = Some(binding);
50        self
51    }
52
53    #[must_use]
54    pub fn with_context_writes(mut self, writes: ContextWrites) -> Self {
55        self.context_writes = writes;
56        self
57    }
58
59    #[must_use]
60    pub fn with_repeat_policy(mut self, repeat_policy: StepRepeatPolicy) -> Self {
61        self.repeat_policy = Some(repeat_policy);
62        self
63    }
64
65    #[must_use]
66    pub fn id(&self) -> &StepId {
67        &self.id
68    }
69
70    #[must_use]
71    pub fn state_id(&self) -> &StateId {
72        &self.state_id
73    }
74
75    #[must_use]
76    pub fn handler_kind(&self) -> &StepHandlerKind {
77        &self.handler_kind
78    }
79
80    #[must_use]
81    pub fn handler_config(&self) -> &StepHandlerConfig {
82        &self.handler_config
83    }
84
85    #[must_use]
86    pub fn retry_policy(&self) -> RetryPolicy {
87        self.retry_policy
88    }
89
90    #[must_use]
91    pub fn timeout(&self) -> Option<StepTimeout> {
92        self.timeout
93    }
94
95    #[must_use]
96    pub fn repeat_policy(&self) -> Option<&StepRepeatPolicy> {
97        self.repeat_policy.as_ref()
98    }
99
100    #[must_use]
101    pub fn dynamic_role_binding(&self) -> Option<&DynamicRoleBinding> {
102        self.dynamic_role_binding.as_ref()
103    }
104
105    #[must_use]
106    pub fn context_writes(&self) -> &ContextWrites {
107        &self.context_writes
108    }
109}