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

pub struct DenoPlugin;

impl Plugin for DenoPlugin {
    fn name(&self) -> &str {
        "deno"
    }

    fn description(&self) -> &str {
        "Deno 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();

        // macOS: ~/Library/Caches/deno, Linux: ~/.cache/deno
        let candidates = [
            home.join("Library").join("Caches").join("deno"),
            home.join(".cache").join("deno"),
        ];

        for cache in candidates {
            if cache.is_dir() {
                let size = utils::dir_size(&cache);
                targets.push(CleanTarget {
                    label: format!("{}", cache.display()),
                    size_bytes: size,
                    action: CleanAction::DeletePath(cache),
                    plugin_name: self.name().to_string(),
                    safety: Safety::Recoverable,
                    explanation: "Deno module cache, re-downloaded as needed".to_string(),
                });
            }
        }

        targets
    }
}
