use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use super::types::{Prd, ProgressEntry, RalphConfig, RalphStatus};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RalphRunState {
pub run_id: String,
pub okr_id: Option<String>,
pub prd: Prd,
pub config: RalphConfig,
pub status: RalphStatus,
pub current_iteration: usize,
pub max_iterations: usize,
#[serde(default)]
pub progress_log: Vec<ProgressEntry>,
#[serde(default)]
pub story_results: Vec<StoryResultEntry>,
pub error: Option<String>,
pub created_at: String,
pub started_at: Option<String>,
pub completed_at: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StoryResultEntry {
pub story_id: String,
pub title: String,
pub passed: bool,
pub iteration: usize,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RalphRunSummary {
pub run_id: String,
pub okr_id: Option<String>,
pub status: RalphStatus,
pub passed: usize,
pub total: usize,
pub current_iteration: usize,
pub created_at: String,
}
#[async_trait]
pub trait RalphStateStore: Send + Sync {
async fn create_run(&self, state: &RalphRunState) -> anyhow::Result<()>;
async fn update_status(&self, run_id: &str, status: RalphStatus) -> anyhow::Result<()>;
async fn update_iteration(&self, run_id: &str, iteration: usize) -> anyhow::Result<()>;
async fn record_story_result(
&self,
run_id: &str,
result: &StoryResultEntry,
) -> anyhow::Result<()>;
async fn append_progress(&self, run_id: &str, entry: &ProgressEntry) -> anyhow::Result<()>;
async fn update_prd(&self, run_id: &str, prd: &Prd) -> anyhow::Result<()>;
async fn set_error(&self, run_id: &str, error: &str) -> anyhow::Result<()>;
async fn complete_run(&self, run_id: &str, status: RalphStatus) -> anyhow::Result<()>;
async fn get_run(&self, run_id: &str) -> anyhow::Result<Option<RalphRunState>>;
async fn list_runs(&self) -> anyhow::Result<Vec<RalphRunSummary>>;
}