package com.psg.dlsysinfo.dl_sysinfo_server.util;

public class NormalizationUtils {

    public static String normalize(String input) {
        if (input == null) return "";
        return input
                .toLowerCase()
                .replaceAll("[^a-z0-9]", "_")
                .replaceAll("_+", "_")
                .replaceAll("^_|_$", "");
    }

    public static String simplifyPublisher(String publisher) {
        String norm = normalize(publisher);
        return switch (norm) {
            case "microsoft_corporation", "microsoft" -> "microsoft";
            case "adobe_systems_incorporated", "adobe_inc" -> "adobe";
            case "oracle_corporation" -> "oracle";
            case "videolan" -> "videolan"; // ensure no unexpected variation
            default -> norm;
        };
    }

    public static String normalizeProduct(String appName) {
        if (appName == null) return "";

        String cleaned = stripJunkFromName(appName);
        String norm = normalize(cleaned);

        return switch (norm) {
            case "vlc_media_player" -> "vlc";
            case "adobe_reader", "acrobat_reader", "adobe_acrobat_reader" -> "acrobat_reader";
            case "java_platform_se", "java", "java_se", "java_platform" -> "jdk"; // adapt based on your CPE data
            case "google_chrome" -> "chrome";
            case "windows_powershell" -> "powershell";
            case "microsoft_teams" -> "teams";
            case "visual_studio_code" -> "vscode";
            default -> norm;
        };
    }

    public static String stripJunkFromName(String input) {
        if (input == null) return "";
        return input
                .replaceAll("(?i)(\\(tm\\)|\\(r\\)|\\(c\\)|™|®|©)", "")
                .replaceAll("\\s+", " ")
                .trim();
    }
}
