made_core/value_objects/ceremony/
ceremony_step.rs1use serde::{Deserialize, Serialize};
2
3use super::{
4 CeremonyChildSpawn, CeremonyStepAggregation, ContextWrites, DynamicRoleBinding, RetryPolicy,
5 StateId, StepHandlerConfig, StepHandlerKind, 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 #[serde(default, skip_serializing_if = "Option::is_none")]
23 spawn: Option<CeremonyChildSpawn>,
24 #[serde(default, skip_serializing_if = "Option::is_none")]
25 aggregation: Option<CeremonyStepAggregation>,
26}
27
28impl CeremonyStep {
29 #[must_use]
30 pub fn new(
31 id: StepId,
32 state_id: StateId,
33 handler_kind: StepHandlerKind,
34 handler_config: StepHandlerConfig,
35 retry_policy: RetryPolicy,
36 timeout: Option<StepTimeout>,
37 ) -> Self {
38 Self {
39 id,
40 state_id,
41 handler_kind,
42 handler_config,
43 retry_policy,
44 timeout,
45 repeat_policy: None,
46 dynamic_role_binding: None,
47 context_writes: ContextWrites::default(),
48 spawn: None,
49 aggregation: None,
50 }
51 }
52
53 #[must_use]
54 pub fn with_dynamic_role_binding(mut self, binding: DynamicRoleBinding) -> Self {
55 self.dynamic_role_binding = Some(binding);
56 self
57 }
58
59 #[must_use]
60 pub fn with_context_writes(mut self, writes: ContextWrites) -> Self {
61 self.context_writes = writes;
62 self
63 }
64
65 #[must_use]
66 pub fn with_repeat_policy(mut self, repeat_policy: StepRepeatPolicy) -> Self {
67 self.repeat_policy = Some(repeat_policy);
68 self
69 }
70
71 #[must_use]
72 pub fn with_spawn(mut self, spawn: CeremonyChildSpawn) -> Self {
73 self.spawn = Some(spawn);
74 self
75 }
76
77 #[must_use]
78 pub fn with_aggregation(mut self, aggregation: CeremonyStepAggregation) -> Self {
79 self.aggregation = Some(aggregation);
80 self
81 }
82
83 #[must_use]
84 pub fn id(&self) -> &StepId {
85 &self.id
86 }
87
88 #[must_use]
89 pub fn state_id(&self) -> &StateId {
90 &self.state_id
91 }
92
93 #[must_use]
94 pub fn handler_kind(&self) -> &StepHandlerKind {
95 &self.handler_kind
96 }
97
98 #[must_use]
99 pub fn handler_config(&self) -> &StepHandlerConfig {
100 &self.handler_config
101 }
102
103 #[must_use]
104 pub fn retry_policy(&self) -> RetryPolicy {
105 self.retry_policy
106 }
107
108 #[must_use]
109 pub fn timeout(&self) -> Option<StepTimeout> {
110 self.timeout
111 }
112
113 #[must_use]
114 pub fn repeat_policy(&self) -> Option<&StepRepeatPolicy> {
115 self.repeat_policy.as_ref()
116 }
117
118 #[must_use]
119 pub fn dynamic_role_binding(&self) -> Option<&DynamicRoleBinding> {
120 self.dynamic_role_binding.as_ref()
121 }
122
123 #[must_use]
124 pub fn context_writes(&self) -> &ContextWrites {
125 &self.context_writes
126 }
127
128 #[must_use]
129 pub fn spawn(&self) -> Option<&CeremonyChildSpawn> {
130 self.spawn.as_ref()
131 }
132
133 #[must_use]
134 pub fn aggregation(&self) -> Option<&CeremonyStepAggregation> {
135 self.aggregation.as_ref()
136 }
137}