/*-
 * ~~~~~~licensing~~~~~~
 * application-shell
 * ==========
 * Copyright (C) 2020 - 2025 EmDev LLC
 * ==========
 * You may not use this file except in accordance with the License Terms of the Copyright
 * Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
 * rights to the Software and any copies are the property of the Copyright Holder. Unless
 * it is explicitly allowed the Copyright Holder, the User is prohibited from using the
 * Software for commercial purposes to provide services to third parties.
 * 
 * The Copyright Holder hereby declares that the Software is provided on an "AS IS".
 * Under no circumstances does the Copyright Holder guarantee or promise that the
 * Software provided by him will be suitable or not suitable for the specific purposes
 * of the User, that the Software will meet all commercial and personal subjective
 * expectations of the User, that the Software will work properly, without technical
 * errors, quickly and uninterruptedly.
 * 
 * Under no circumstances shall the Copyright Holder or its Affiliates is not liable
 * to the User for any direct or indirect losses of the User, his expenses or actual
 * damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
 * or damage to data, property, etc.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.platform.integration.applications.shell;

import java.util.function.Function;

import org.apache.karaf.shell.support.ansi.SimpleAnsi;

import ru.entaxy.platform.base.support.karaf.shell.ShellTableExt;

public class ApplicationShell {

    public static final String COMMAND_SCOPE = "entaxy";

    public static final String COMMAND_APP_NAME_PREFIX = "app-";

    public static final String COMMAND_PROJECT_NAME_PREFIX = "project-";

    public static String projectCommandName(String name) {
        return COMMAND_PROJECT_NAME_PREFIX.concat("-").concat(name);
    }

    public static final String PROJECT_KEY = "ApplicationShell.project";

    public static final String PROJECT_VERSION_KEY = "ApplicationShell.projectVersion";

    public static final String APPLICATION_KEY = "ApplicationShell.application";

    public static final String APPLICATION_VERSION_KEY = "ApplicationShell.applicationVersion";

    public static final String APPLICATION_REVISION_KEY = "ApplicationShell.applicationRevision";

    public static final String APPLICATION_CONFIG_KEY = "ApplicationShell.applicationConfig";

    // Welocme color
    public static String WLC = "\u001B[36m";
    // OK color: High Intensity Foreground Color: Green
    public static String OKC = SimpleAnsi.COLOR_GREEN;
    // WARN color: High Intensity Foreground Color: Yellow
    public static String WARNC = SimpleAnsi.COLOR_YELLOW;
    // CRITICAL color: High Intensity Foreground Color: Red
    public static String CRT = SimpleAnsi.COLOR_RED + SimpleAnsi.INTENSITY_BOLD;
    // reset colors
    public static String NOR = "\33[0m";

    public static String COLOR_REQUIRED = CRT;
    public static String COLOR_INCLUDED = OKC + SimpleAnsi.INTENSITY_BOLD;
    public static String COLOR_IGNORED = SimpleAnsi.COLOR_BLUE + SimpleAnsi.INTENSITY_BOLD;
    public static String COLOR_GHOST = WARNC + SimpleAnsi.INTENSITY_BOLD;

    public static String COLOR_GRAY = "\33[38;2;100;100;100m" + SimpleAnsi.INTENSITY_BOLD;

    public static String COLOR_RESET = NOR + SimpleAnsi.INTENSITY_NORMAL;

    public static String colRequired(String data) {
        return COLOR_REQUIRED + data + COLOR_RESET;
    }

    public static String colIncluded(String data) {
        return COLOR_INCLUDED + data + COLOR_RESET;
    }

    public static String colIgnored(String data) {
        return COLOR_IGNORED + data + COLOR_RESET;
    }

    public static String colGhost(String data) {
        return COLOR_GHOST + data + COLOR_RESET;
    }

    public static Function<String, String> normalColorProvider =
            (str -> SimpleAnsi.RESET + SimpleAnsi.INTENSITY_NORMAL);

    public static Function<ShellTableExt.CellData, String> normalColorProviderExt =
            (cellData -> SimpleAnsi.RESET + SimpleAnsi.INTENSITY_NORMAL);

    public static Function<String, String> itemStatusColorProvider = (str -> {
        if ("+".equals(str))
            return COLOR_INCLUDED;
        else if ("-".equals(str))
            return COLOR_IGNORED;
        else if ("!".equals(str))
            return COLOR_REQUIRED;
        else if ("?".equals(str))
            return COLOR_GHOST;
        else
            return "";
    });

    public static Function<String, String> requirementStatusColorProvider = (str -> {
        if ("V".equals(str))
            return COLOR_INCLUDED;
        else if ("X".equals(str))
            return COLOR_REQUIRED;
        else
            return "";
    });

}
