use serde_json::{Map, Value, json};
use super::{Action, str_of};
pub(crate) const WORKFLOW: &str = "workflow";
pub(crate) const CLEAR: &str = "clear-workflow";
pub(super) fn encode(workspace: &str, agent: &str, config: Option<&str>) -> Value {
match config {
Some(config) => json!({ "op": WORKFLOW, "workspace": workspace,
"agent": agent, "config": config }),
None => json!({ "op": CLEAR, "workspace": workspace, "agent": agent }),
}
}
pub(super) fn decode(op: &str, o: &Map<String, Value>) -> Result<Action, String> {
Ok(Action::Workflow {
workspace: str_of(o, "workspace")?,
agent: str_of(o, "agent")?,
config: if op == WORKFLOW {
Some(str_of(o, "config")?)
} else {
None
},
})
}