use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sqlx::FromRow;
use uuid::Uuid;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, FromRow)]
pub struct AgentTraceModel {
    pub id: Uuid,
    pub invocation: Uuid,
    pub conversation: Uuid,
    pub sequence: i32,
    pub phase: String,
    pub content: Option<String>,
    pub tool_calls: Option<Value>,
    pub tool_results: Option<Value>,
    pub input_tokens: Option<i64>,
    pub output_tokens: Option<i64>,
    pub metadata: Option<Value>,
    pub created_at: DateTime<Utc>,
}

impl AgentTraceModel {
    pub fn phase_label(&self) -> &str {
        match self.phase.as_str() {
            "think" => "Thinking",
            "answer" => "Answering",
            "act" => "Acting",
            "summarize" => "Summarizing",
            _ => &self.phase,
        }
    }
}
