1#[allow(unused_imports)]
2use crate::{Act, Catch, ModelBase, Timeout, Vars, model::Branch};
3use serde::{Deserialize, Serialize};
4use serde_json::Value as JsonValue;
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Step {
8 #[serde(default)]
9 pub name: String,
10
11 #[serde(default)]
12 pub desc: String,
13
14 #[serde(default)]
15 pub id: String,
16
17 #[serde(default)]
18 pub inputs: Vars,
19
20 #[serde(default)]
21 pub outputs: Vars,
22
23 #[serde(default)]
24 pub tag: String,
25
26 #[serde(default)]
27 pub r#if: Option<String>,
28
29 #[serde(default)]
30 pub branches: Vec<Branch>,
31
32 #[serde(default)]
33 pub next: Option<String>,
34
35 #[serde(default)]
36 pub acts: Vec<Act>,
37
38 #[serde(default)]
39 pub catches: Vec<Catch>,
40
41 #[serde(default)]
42 pub timeout: Vec<Timeout>,
43
44 #[serde(default)]
45 pub setup: Vec<Act>,
46}
47
48impl ModelBase for Step {
49 fn id(&self) -> &str {
50 &self.id
51 }
52}
53
54impl Step {
55 pub fn new() -> Self {
56 Default::default()
57 }
58 pub fn with_id(mut self, id: &str) -> Self {
59 self.id = id.to_string();
60 self
61 }
62
63 pub fn with_name(mut self, name: &str) -> Self {
64 self.name = name.to_string();
65 self
66 }
67
68 pub fn with_tag(mut self, tag: &str) -> Self {
69 self.tag = tag.to_string();
70 self
71 }
72
73 pub fn with_act(mut self, stmt: Act) -> Self {
74 self.acts.push(stmt);
75 self
76 }
77
78 pub fn with_next(mut self, next: &str) -> Self {
79 self.next = Some(next.to_string());
80 self
81 }
82
83 pub fn with_if(mut self, r#if: &str) -> Self {
84 self.r#if = Some(r#if.to_string());
85 self
86 }
87
88 pub fn with_input(mut self, name: &str, value: JsonValue) -> Self {
89 self.inputs.insert(name.to_string(), value);
90 self
91 }
92
93 pub fn with_output(mut self, name: &str, value: JsonValue) -> Self {
94 self.outputs.insert(name.to_string(), value);
95 self
96 }
97
98 pub fn with_branch(mut self, build: fn(Branch) -> Branch) -> Self {
99 let branch = Branch::default();
100 self.branches.push(build(branch));
101 self
102 }
103
104 pub fn with_catch(mut self, build: fn(Catch) -> Catch) -> Self {
105 let catch = Catch::default();
106 self.catches.push(build(catch));
107 self
108 }
109
110 pub fn with_timeout(mut self, build: fn(Timeout) -> Timeout) -> Self {
111 let timeout = Timeout::default();
112 self.timeout.push(build(timeout));
113 self
114 }
115
116 pub fn with_setup(mut self, build: fn(Vec<Act>) -> Vec<Act>) -> Self {
117 let stmts = Vec::new();
118 self.setup = build(stmts);
119 self
120 }
121}