use std::path::Path;

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

pub struct MavenPlugin;

impl Plugin for MavenPlugin {
    fn name(&self) -> &str {
        "maven"
    }

    fn description(&self) -> &str {
        "Maven build outputs (target/)"
    }

    fn scan_directory(&self, dir: &Path) -> Vec<CleanTarget> {
        let mut targets = Vec::new();

        let pom = dir.join("pom.xml");
        if pom.exists() {
            let target_dir = dir.join("target");
            if target_dir.is_dir() {
                let size = utils::dir_size(&target_dir);
                targets.push(CleanTarget {
                    label: format!("{}", target_dir.display()),
                    size_bytes: size,
                    action: CleanAction::DeletePath(target_dir),
                    plugin_name: self.name().to_string(),
                    safety: Safety::Recoverable,
                    explanation: "Maven build output, recreate with `mvn package`".to_string(),
                });
            }
        }

        targets
    }

    fn markers(&self) -> &'static [&'static str] {
        &["pom.xml"]
    }
}
