use std::path::PathBuf;

fn main() {
    let data_dir: PathBuf = dirs_next().join("outlay");
    let db_path = data_dir.join("outlay.db");

    println!("Database path: {}", db_path.display());

    if db_path.exists() {
        println!("Removing existing database for a clean seed...");
        std::fs::remove_file(&db_path).expect("Failed to remove existing database");
    }

    let db = outlay_core::db::Database::open(&db_path)
        .expect("Failed to open database");

    println!("Seeding demo data (2 years of realistic usage)...");

    outlay_core::seed::seed_demo_data(&db)
        .expect("Failed to seed demo data");

    println!("Done! Restart Outlay to see the demo data.");
}

fn dirs_next() -> PathBuf {
    if let Ok(dir) = std::env::var("XDG_DATA_HOME") {
        PathBuf::from(dir)
    } else if let Ok(home) = std::env::var("HOME") {
        PathBuf::from(home).join(".local").join("share")
    } else {
        PathBuf::from(".")
    }
}
