use serde::{Deserialize, Serialize};
use serde_json::Value;
use argonauts_core::events::run::RunOutcome;
use argonauts_core::events::workflow::StepEnd;
use argonauts_core::names::WorkflowId;
use argonauts_core::workflow::{StandardPhase, Step, StepRef, WorkflowRef};
pub mod authors;
pub mod brief;
pub mod builtin;
pub mod change;
pub mod conditions;
pub mod kinds;
pub mod naming;
pub mod params;
pub mod replay;
pub mod runner;
pub mod shape;
pub mod sizing;
pub mod validate;
pub mod yaml;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct StepAt {
pub step: StepRef,
pub round: u32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StepCall {
pub at: StepAt,
pub depth: u32,
pub standard: StandardPhase,
pub step: Step,
pub item: Option<Value>,
}
pub fn describe(step: &StepRef) -> String {
let path: Vec<String> = step
.path
.iter()
.map(|index| (index + 1).to_string())
.collect();
format!("phase {}, step {}", step.phase + 1, path.join("."))
}
impl StepCall {
pub fn workflow(&self) -> &WorkflowId {
&self.at.step.workflow
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct StepDone {
pub end: StepEnd,
pub summary: Option<String>,
pub flow: Flow,
}
impl StepDone {
pub fn done(summary: impl Into<String>) -> Self {
Self {
end: StepEnd::Done,
summary: Some(summary.into()),
flow: Flow::Continue,
}
}
pub fn skipped(summary: impl Into<String>) -> Self {
Self {
end: StepEnd::Skipped,
summary: Some(summary.into()),
flow: Flow::Continue,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Flow {
Continue,
Finish(RunOutcome),
Switch(WorkflowRef),
}