use std::path::Path;

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

pub struct TrashPlugin;

impl Plugin for TrashPlugin {
    fn name(&self) -> &str {
        "trash"
    }

    fn description(&self) -> &str {
        "macOS Trash (already deleted by user)"
    }

    #[cfg(target_os = "macos")]
    fn is_available(&self) -> bool {
        true
    }

    #[cfg(not(target_os = "macos"))]
    fn is_available(&self) -> bool {
        false
    }

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

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

        let trash_dir = utils::home_dir().join(".Trash");
        if trash_dir.is_dir() {
            let size = utils::dir_size(&trash_dir);
            targets.push(CleanTarget {
                label: format!("{} (contents)", trash_dir.display()),
                size_bytes: size,
                action: CleanAction::DeleteContents(trash_dir),
                plugin_name: self.name().to_string(),
                safety: Safety::Unsafe,
                explanation: String::new(),
            });
        }

        targets
    }
}
