1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use crate::{
	callbacks::PyEventCallbackInterface,
	comm::ChannelHandler,
	config::Config,
	cross::{CLRepr, StringType},
};

use super::Workflow;

/// Builder for constructing a `Workflow`.
pub struct WorkflowBuilder {
	name: Option<String>,
	id: String,
	import: Option<String>,
	attr: Option<String>,
	code: Option<String>,
	arguments: Vec<CLRepr>,
	config: Option<Config>,
}

impl WorkflowBuilder {
	/// Creates a new `WorkflowBuilder` with the required workflow ID.
	pub fn new(id: &str) -> Self {
		WorkflowBuilder {
			name: None,
			id: id.to_string(),
			import: None,
			attr: None,
			code: None,
			arguments: Vec::new(),
			config: None,
		}
	}

	/// Workflow from given workflow.
	pub fn from_workflow(workflow: Workflow) -> Self {
		WorkflowBuilder {
			name: Some(workflow.name),
			id: workflow.id,
			import: Some(workflow.import),
			attr: Some(workflow.attr),
			code: workflow.code,
			arguments: workflow.arguments,
			config: workflow.config,
		}
	}

	/// Sets the name of the workflow.
	pub fn name(mut self, name: &str) -> Self {
		self.name = Some(name.to_string());
		self
	}

	/// Sets the import statement for the workflow.
	pub fn import(mut self, import: Option<String>) -> Self {
		self.import = import;
		self
	}

	/// Sets the attribute representing the start function of the workflow.
	pub fn attr(mut self, attr: Option<String>) -> Self {
		self.attr = attr;
		self
	}

	/// Sets the Python code for the workflow.
	pub fn code(mut self, code: Option<String>) -> Self {
		self.code = code;
		self
	}
	/// add arguments to the workflow
	pub fn arguments(mut self, arguments: Vec<CLRepr>) -> Self {
		self.arguments = arguments;
		self
	}

	/// Sets the configuration for the workflow.
	pub fn config(mut self, config: Config) -> Self {
		self.config = Some(config);
		self
	}

	/// Builds the `Workflow` using the configured parameters.
	pub fn build(self) -> Workflow {
		Workflow {
			name: self.name.unwrap_or_else(|| self.id.clone()),
			id: self.id,
			import: self.import.unwrap_or_default(),
			attr: self.attr.unwrap_or_default(),
			code: self.code,
			arguments: self.arguments,
			config: self.config,
		}
	}
}