pub mod gauge;
pub mod history;

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DashboardData {
    pub tokens_used: u64,
    pub tokens_saved: u64,
    pub cost_usd_avoided: f64,
    pub period_days: u32,
    pub daily_buckets: Vec<DailyBucket>,
    pub project_breakdown: Vec<ProjectBreakdown>,
    pub skill_usage: HashMap<String, u64>,
    pub top_lens: String,
}

impl DashboardData {
    pub fn savings_pct(&self) -> f64 {
        let total = self.tokens_used + self.tokens_saved;
        if total == 0 {
            return 0.0;
        }
        self.tokens_saved as f64 / total as f64 * 100.0
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DailyBucket {
    pub date: String,
    pub tokens_sent: u64,
    pub tokens_saved: u64,
    pub cost_usd_avoided: f64,
    pub skills_used: HashMap<String, u64>,
    pub top_lens: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectBreakdown {
    pub project_hash: String,
    pub name: String,
    pub total_tokens: u64,
    pub savings_pct: f64,
    pub last_active: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModelAttribution {
    pub model_id: String,
    pub tokens_charged: u64,
    pub cost_usd: f64,
    pub period: String,
}
