use chrono::{DateTime, Utc};
use ironflow_store::models::{Step, StepKind, StepStatus};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use uuid::Uuid;
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize, Deserialize)]
pub struct StepResponse {
pub id: Uuid,
pub run_id: Uuid,
pub name: String,
#[cfg_attr(feature = "openapi", schema(value_type = String))]
pub kind: StepKind,
pub position: u32,
pub status: StepStatus,
#[cfg_attr(feature = "openapi", schema(value_type = Option<std::collections::HashMap<String, serde_json::Value>>))]
pub input: Option<Value>,
#[cfg_attr(feature = "openapi", schema(value_type = Option<std::collections::HashMap<String, serde_json::Value>>))]
pub output: Option<Value>,
pub error: Option<String>,
pub duration_ms: u64,
#[cfg_attr(feature = "openapi", schema(value_type = f64))]
pub cost_usd: Decimal,
pub input_tokens: Option<u64>,
pub output_tokens: Option<u64>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
pub dependencies: Vec<Uuid>,
#[cfg_attr(feature = "openapi", schema(value_type = Option<serde_json::Value>))]
pub debug_messages: Option<Value>,
}
impl StepResponse {
pub fn with_dependencies(step: Step, dependencies: Vec<Uuid>) -> Self {
StepResponse {
id: step.id,
run_id: step.run_id,
name: step.name,
kind: step.kind,
position: step.position,
status: step.status.state,
input: step.input,
output: step.output,
error: step.error,
duration_ms: step.duration_ms,
cost_usd: step.cost_usd,
input_tokens: step.input_tokens,
output_tokens: step.output_tokens,
created_at: step.created_at,
updated_at: step.updated_at,
started_at: step.started_at,
completed_at: step.completed_at,
dependencies,
debug_messages: step.debug_messages,
}
}
}
impl From<Step> for StepResponse {
fn from(step: Step) -> Self {
Self::with_dependencies(step, Vec::new())
}
}