use std::path::Path;

use crate::plugin::{CleanAction, CleanTarget, Plugin, Safety};
use crate::utils;

pub struct BunPlugin;

impl Plugin for BunPlugin {
    fn name(&self) -> &str {
        "bun"
    }

    fn description(&self) -> &str {
        "Bun install cache"
    }

    fn scan_directory(&self, _dir: &Path) -> Vec<CleanTarget> {
        Vec::new()
    }

    fn global_targets(&self) -> Vec<CleanTarget> {
        let mut targets = Vec::new();
        let home = utils::home_dir();

        let bun_install = home.join(".bun/install/cache");
        if bun_install.is_dir() {
            let size = utils::dir_size(&bun_install);
            targets.push(CleanTarget {
                label: format!("{}", bun_install.display()),
                size_bytes: size,
                action: CleanAction::DeletePath(bun_install),
                plugin_name: self.name().to_string(),
                safety: Safety::Recoverable,
                explanation: "Bun package cache, re-downloaded as needed".to_string(),
            });
        }

        targets
    }
}
