//! Evaluation configuration for LLM prompt optimization.

use std::path::PathBuf;

use serde::Deserialize;

/// Configuration for the LLM evaluation subsystem.
///
/// The evaluation system tracks every LLM extraction attempt with full
/// context (prompt, content, response, timing), enabling data-driven
/// prompt optimization and regression detection.
#[derive(Debug, Clone, Deserialize)]
#[serde(default)]
pub struct EvalConfig {
    /// Save observations during scans (opt-in, default: false).
    ///
    /// When enabled, every LLM extraction attempt is logged to SQLite
    /// with full context for later analysis.
    pub save_observations: bool,

    /// Path to the SQLite database for observations.
    ///
    /// Default: `~/.aphoria/eval/observations.db`
    pub database_path: PathBuf,

    /// Default directory for test fixtures.
    ///
    /// Used by the evaluation harness to load expected claim sets.
    pub fixtures_dir: PathBuf,

    /// Regression threshold as a decimal (e.g., 0.05 = 5%).
    ///
    /// If claim accuracy drops by more than this amount between
    /// prompt versions, it's flagged as a regression.
    pub regression_threshold: f64,

    /// Maximum concurrent LLM calls during evaluation runs.
    pub max_concurrent: usize,

    /// Retention: number of days to keep observations.
    pub retention_days: u64,

    /// Retention: maximum observations to keep regardless of age.
    ///
    /// This ensures we always have enough data for analysis even
    /// if the time window is short.
    pub retention_max_count: usize,
}

impl Default for EvalConfig {
    fn default() -> Self {
        Self {
            save_observations: false,
            database_path: default_database_path(),
            fixtures_dir: PathBuf::from("tests/llm_fixtures"),
            regression_threshold: 0.05,
            max_concurrent: 5,
            retention_days: 30,
            retention_max_count: 1000,
        }
    }
}

/// Get the default database path for observations.
fn default_database_path() -> PathBuf {
    dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(".aphoria/eval/observations.db")
}
