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

pub struct LuaPlugin;

impl Plugin for LuaPlugin {
    fn name(&self) -> &str {
        "lua"
    }

    fn description(&self) -> &str {
        "LuaRocks package cache"
    }

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

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

        let luarocks = utils::home_dir().join(".luarocks");
        if luarocks.is_dir() {
            let size = utils::dir_size(&luarocks);
            targets.push(CleanTarget {
                label: format!("{}", luarocks.display()),
                size_bytes: size,
                action: CleanAction::DeletePath(luarocks),
                plugin_name: self.name().to_string(),
                safety: Safety::Recoverable,
                explanation: "LuaRocks package cache, reinstall with `luarocks install`"
                    .to_string(),
            });
        }

        targets
    }
}
