use chrono::{DateTime, Utc};
use ironflow_store::models::{Run, RunStatus, TriggerKind};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use super::StepResponse;
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize, Deserialize)]
pub struct RunResponse {
pub id: Uuid,
pub workflow_name: String,
pub status: RunStatus,
pub trigger: TriggerKind,
pub error: Option<String>,
pub retry_count: u32,
pub max_retries: u32,
#[cfg_attr(feature = "openapi", schema(value_type = f64))]
pub cost_usd: Decimal,
pub duration_ms: u64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub started_at: Option<DateTime<Utc>>,
pub completed_at: Option<DateTime<Utc>>,
}
impl From<Run> for RunResponse {
fn from(run: Run) -> Self {
RunResponse {
id: run.id,
workflow_name: run.workflow_name,
status: run.status.state,
trigger: run.trigger,
error: run.error,
retry_count: run.retry_count,
max_retries: run.max_retries,
cost_usd: run.cost_usd,
duration_ms: run.duration_ms,
created_at: run.created_at,
updated_at: run.updated_at,
started_at: run.started_at,
completed_at: run.completed_at,
}
}
}
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize)]
pub struct RunDetailResponse {
pub run: RunResponse,
pub steps: Vec<StepResponse>,
}
#[cfg_attr(feature = "openapi", derive(utoipa::IntoParams, utoipa::ToSchema))]
#[derive(Debug, Deserialize)]
pub struct ListRunsQuery {
pub workflow: Option<String>,
pub status: Option<RunStatus>,
pub has_steps: Option<bool>,
pub page: Option<u32>,
pub per_page: Option<u32>,
}