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

pub struct VscodePlugin;

impl Plugin for VscodePlugin {
    fn name(&self) -> &str {
        "vscode"
    }

    fn description(&self) -> &str {
        "VS Code caches"
    }

    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/Application Support/Code/Cache
        let candidates = [
            home.join("Library")
                .join("Application Support")
                .join("Code")
                .join("Cache"),
            home.join("Library")
                .join("Application Support")
                .join("Code")
                .join("CachedData"),
            home.join(".config").join("Code").join("Cache"),
            home.join(".config").join("Code").join("CachedData"),
        ];

        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: "VS Code cache, regenerated automatically".to_string(),
                });
            }
        }

        targets
    }
}
