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