use crate::{
callbacks::PyEventCallbackInterface,
comm::ChannelHandler,
config::Config,
cross::{CLRepr, StringType},
};
use super::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 {
pub fn new(id: &str) -> Self {
WorkflowBuilder {
name: None,
id: id.to_string(),
import: None,
attr: None,
code: None,
arguments: Vec::new(),
config: None,
}
}
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,
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_string());
self
}
pub fn import(mut self, import: Option<String>) -> Self {
self.import = import;
self
}
pub fn attr(mut self, attr: Option<String>) -> Self {
self.attr = attr;
self
}
pub fn code(mut self, code: Option<String>) -> Self {
self.code = code;
self
}
pub fn arguments(mut self, arguments: Vec<CLRepr>) -> Self {
self.arguments = arguments;
self
}
pub fn config(mut self, config: Config) -> Self {
self.config = Some(config);
self
}
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,
}
}
}