use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlueprintWorkflow {
pub description: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub graph: Option<String>,
}
impl BlueprintWorkflow {
pub fn new(description: String) -> Self {
Self {
description,
graph: None,
}
}
pub fn with_graph(description: String, graph: String) -> Self {
Self {
description,
graph: Some(graph),
}
}
pub fn has_graph(&self) -> bool {
self.graph.is_some()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_blueprint_creation() {
let bp = BlueprintWorkflow::new("Test workflow".to_string());
assert_eq!(bp.description, "Test workflow");
assert!(!bp.has_graph());
}
#[test]
fn test_blueprint_with_graph() {
let bp = BlueprintWorkflow::with_graph("Test".to_string(), "graph TD\nA --> B".to_string());
assert!(bp.has_graph());
}
#[test]
fn test_blueprint_serialization() {
let bp = BlueprintWorkflow::with_graph(
"Workflow".to_string(),
"graph LR\nStart --> End".to_string(),
);
let json = serde_json::to_string(&bp).unwrap();
let deserialized: BlueprintWorkflow = serde_json::from_str(&json).unwrap();
assert_eq!(bp.description, deserialized.description);
assert_eq!(bp.graph, deserialized.graph);
}
}