use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use uuid::Uuid;
use crate::node::Node;
use crate::state::StateSchema;
use crate::template::Template;
use ts_rs::TS;
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
pub struct Workflow {
pub version: String,
#[serde(default)]
#[ts(optional=nullable)]
pub state: Option<WorkflowState>,
#[serde(default)]
#[ts(optional, as = "Option<Vec<Template>>")]
pub templates: Vec<Template>,
pub nodes: Vec<Node>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema, TS)]
pub struct WorkflowState {
#[serde(default)]
pub schema: Vec<StateSchema>,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
pub struct WorkflowRun {
pub id: Uuid,
pub workflow: Workflow,
pub status: WorkflowStatus,
pub params: HashMap<String, String>,
pub tasks: Vec<Uuid>,
pub started_at: DateTime<Utc>,
#[serde(default)]
#[ts(optional=nullable)]
pub ended_at: Option<DateTime<Utc>>,
#[ts(skip)]
#[serde(skip)]
pub bundle_path: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TS)]
pub enum WorkflowStatus {
Pending,
Running,
Completed,
Failed,
AwaitingTrigger,
Canceled,
}