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

pub struct JetbrainsPlugin;

impl Plugin for JetbrainsPlugin {
    fn name(&self) -> &str {
        "jetbrains"
    }

    fn description(&self) -> &str {
        "JetBrains IDE 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/Caches/JetBrains
        let mac_caches = home.join("Library").join("Caches").join("JetBrains");
        if mac_caches.is_dir() {
            let size = utils::dir_size(&mac_caches);
            targets.push(CleanTarget {
                label: format!("{}", mac_caches.display()),
                size_bytes: size,
                action: CleanAction::DeletePath(mac_caches),
                plugin_name: self.name().to_string(),
                safety: Safety::Recoverable,
                explanation: "JetBrains IDE caches, regenerated on next launch".to_string(),
            });
        }

        // Linux: ~/.cache/JetBrains
        let linux_caches = home.join(".cache").join("JetBrains");
        if linux_caches.is_dir() {
            let size = utils::dir_size(&linux_caches);
            targets.push(CleanTarget {
                label: format!("{}", linux_caches.display()),
                size_bytes: size,
                action: CleanAction::DeletePath(linux_caches),
                plugin_name: self.name().to_string(),
                safety: Safety::Recoverable,
                explanation: "JetBrains IDE caches, regenerated on next launch".to_string(),
            });
        }

        targets
    }
}
