use std::time::Instant;

use crate::agent::persistence::types::{ActiveAgentRun, AgentRunContext};
use crate::error::AiResult;

impl super::types::AgentRuntime {
    pub async fn start_run(
        &self,
        run_context: Option<&AgentRunContext>,
    ) -> AiResult<ActiveAgentRun> {
        let Some(run_context) = run_context else {
            return Ok(ActiveAgentRun {
                conversation_id: None,
                message_id: None,
                invocation_id: None,
                session_id: None,
                user_id: None,
                started_at: Instant::now(),
                current_step: 0,
            });
        };

        Ok(ActiveAgentRun {
            conversation_id: run_context.conversation_id,
            message_id: None,
            invocation_id: run_context.invocation_id,
            session_id: run_context.session_id,
            user_id: run_context.user_id,
            started_at: Instant::now(),
            current_step: 0,
        })
    }
}
