use std::path::Path;

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

pub struct UvPlugin;

impl Plugin for UvPlugin {
    fn name(&self) -> &str {
        "uv"
    }

    fn description(&self) -> &str {
        "uv Python package manager 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/uv, Linux: ~/.cache/uv
        let candidates = [
            home.join("Library").join("Caches").join("uv"),
            home.join(".cache").join("uv"),
        ];

        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: "uv package cache, re-downloaded as needed".to_string(),
                });
            }
        }

        targets
    }
}
