use std::path::Path;

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

pub struct AngularPlugin;

impl Plugin for AngularPlugin {
    fn name(&self) -> &str {
        "angular"
    }

    fn description(&self) -> &str {
        "Angular CLI build cache"
    }

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

        let angular_json = dir.join("angular.json");
        if angular_json.exists() {
            let angular_cache = dir.join(".angular");
            if angular_cache.is_dir() {
                let size = utils::dir_size(&angular_cache);
                targets.push(CleanTarget {
                    label: format!("{}", angular_cache.display()),
                    size_bytes: size,
                    action: CleanAction::DeletePath(angular_cache),
                    plugin_name: self.name().to_string(),
                    safety: Safety::Recoverable,
                    explanation: "Angular build cache, regenerated on next build".to_string(),
                });
            }
        }

        targets
    }

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