use std::path::Path;

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

pub struct ExpoPlugin;

impl Plugin for ExpoPlugin {
    fn name(&self) -> &str {
        "expo"
    }

    fn description(&self) -> &str {
        "Expo/React Native cache"
    }

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

        // app.json is the standard Expo config
        let app_json = dir.join("app.json");
        if app_json.exists() {
            let expo_dir = dir.join(".expo");
            if expo_dir.is_dir() {
                let size = utils::dir_size(&expo_dir);
                targets.push(CleanTarget {
                    label: format!("{}", expo_dir.display()),
                    size_bytes: size,
                    action: CleanAction::DeletePath(expo_dir),
                    plugin_name: self.name().to_string(),
                    safety: Safety::Recoverable,
                    explanation: "Expo cache, regenerated with `expo start`".to_string(),
                });
            }
        }

        targets
    }

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