use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use ironflow_store::entities::{HistoryGranularity, HistoryPeriod};
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize)]
pub struct StatsResponse {
pub total_runs: u64,
pub completed_runs: u64,
pub failed_runs: u64,
pub cancelled_runs: u64,
pub active_runs: u64,
pub success_rate_percent: f64,
pub total_cost_usd: Decimal,
pub total_duration_ms: u64,
}
#[cfg_attr(feature = "openapi", derive(utoipa::IntoParams))]
#[derive(Debug, Deserialize)]
pub struct StatsHistoryQuery {
pub workflow: Option<String>,
pub period: Option<HistoryPeriod>,
pub granularity: Option<HistoryGranularity>,
}
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize)]
pub struct StatsHistoryResponse {
pub period: HistoryPeriod,
pub granularity: HistoryGranularity,
pub workflow: Option<String>,
pub buckets: Vec<StatsHistoryBucketResponse>,
}
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Debug, Serialize)]
pub struct StatsHistoryBucketResponse {
pub time: DateTime<Utc>,
pub completed: u64,
pub failed: u64,
pub cancelled: u64,
pub avg_duration_ms: u64,
pub p95_duration_ms: u64,
pub total_cost_usd: Decimal,
}