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

pub struct CondaPlugin;

impl Plugin for CondaPlugin {
    fn name(&self) -> &str {
        "conda"
    }

    fn description(&self) -> &str {
        "Conda/Miniconda package 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();
        for base in ["miniconda3", "anaconda3", "miniforge3"] {
            let pkgs = home.join(base).join("pkgs");
            if pkgs.is_dir() {
                let size = utils::dir_size(&pkgs);
                targets.push(CleanTarget {
                    label: format!("{}", pkgs.display()),
                    size_bytes: size,
                    action: CleanAction::DeletePath(pkgs),
                    plugin_name: self.name().to_string(),
                    safety: Safety::Recoverable,
                    explanation: "Conda package cache, re-downloaded as needed".to_string(),
                });
            }
        }

        targets
    }
}
