use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct WorkflowSchema {
#[serde(rename = "type", default)]
pub workflow_type: WorkflowType,
#[serde(default)]
pub edges: Vec<Edge>,
#[serde(default)]
pub conditions: Vec<Condition>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum WorkflowType {
#[default]
Single,
Sequential,
Parallel,
Graph,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Edge {
pub from: String,
pub to: String,
#[serde(default)]
pub condition: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub from_port: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub to_port: Option<String>,
}
impl Edge {
pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self {
Self {
from: from.into(),
to: to.into(),
condition: None,
from_port: None,
to_port: None,
}
}
pub fn conditional(
from: impl Into<String>,
to: impl Into<String>,
condition: impl Into<String>,
) -> Self {
Self {
from: from.into(),
to: to.into(),
condition: Some(condition.into()),
from_port: None,
to_port: None,
}
}
pub fn with_from_port(mut self, port: impl Into<String>) -> Self {
self.from_port = Some(port.into());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Condition {
pub id: String,
pub expression: String,
#[serde(default)]
pub description: String,
}
pub const START: &str = "START";
pub const END: &str = "END";