/*-
 * ~~~~~~licensing~~~~~~
 * application-management
 * ==========
 * 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.management;

import ru.entaxy.esb.platform.base.management.core.Qualifier;
import ru.entaxy.esb.platform.base.management.core.api.MBeanAnnotated;
import ru.entaxy.esb.platform.base.management.core.api.MBeanExportPolicy;
import ru.entaxy.esb.platform.base.management.core.api.Operation;
import ru.entaxy.esb.platform.base.management.core.api.Parameter;

import java.util.List;
import java.util.Map;

@MBeanAnnotated(policy = MBeanExportPolicy.ANNOTATED_ONLY)
public interface ApplicationsMBean {

    public static final String MODULE_JMX_DOMAIN = "ru.entaxy.cicd";

    public static final String MAIN_MODULE_KEY = "module";

    public static final String MAIN_MODULE_KEY_VALUE = "applications";

    public static final Qualifier Q_MAIN_MODULE = new Qualifier(MAIN_MODULE_KEY, MAIN_MODULE_KEY_VALUE);

    public static final String Q_MAIN_MODULE_S = MODULE_JMX_DOMAIN + ":" + MAIN_MODULE_KEY + "=" + MAIN_MODULE_KEY_VALUE;

    @Operation(desc = "Gets tree")
    String readAsTree() throws Exception;

    @Operation(desc = "Import project from repository")
    void importFromRepository(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "mavenUrl", desc = "Maven URL of the application") String mavenUrl
    ) throws Exception;

    @Operation(desc = "Import project from base64 string")
    void importFromBase64String(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "fileContentBase64String",
                    desc = "The application file content encoded into base64 string") String fileContentBase64
    ) throws Exception;

    @Operation(desc = "Remove application")
    void removeApplication(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName
    ) throws Exception;

    @Operation(desc = "List application items")
    List<Map<String, Object>> listApplicationItems(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion
    ) throws Exception;

    @Operation(desc = "List application requirements")
    List<Map<String, Object>> listApplicationRequirements(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion
    ) throws Exception;

    @Operation(desc = "Read last and installed revision of the application version")
    Map<String, String> readApplicationVersionLastAndInstalledRevision(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion
    ) throws Exception;

    @Operation(desc = "Read application item types")
    List<String> readApplicationItemTypes();

    @Operation(desc = "Read project item scopes")
    List<String> readApplicationItemScopes();

    @Operation(desc = "Remove application version")
    void removeVersion(@Parameter(name = "storage", desc = "Name of the storage") String storage,
                       @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
                       @Parameter(name = "versionToRemove", desc = "Version to remove") String versionToRemove
    )  throws Exception;

    @Operation(desc = "Create revision for application version")
    void createRevision(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "prototypeRevision", desc = "Existent revision to base on") int prototypeRevision
    ) throws Exception;

    @Operation(desc = "Configure application revision")
    void configureRevision(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision
    ) throws Exception;

    @Operation(desc = "Deploy application revision")
    void deployRevision(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision
    ) throws Exception;

    @Operation(desc = "Install application revision")
    void installRevision(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision
    ) throws Exception;

    @Operation(desc = "Uninstall application revision")
    void uninstallRevision(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision
    ) throws Exception;

    @Operation(desc = "Get application revision status")
    String readRevisionStatus(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision
    ) throws Exception;

    @Operation(desc = "List application revision configurations")
    List<Map<String, String>> listRevisionConfigurations(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision
    ) throws Exception;

    @Operation(desc = "Read application revision configuration")
    Map<String, Object> readRevisionConfiguration(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision,
            @Parameter(name = "configId", desc = "Configuration Id") String configId
    ) throws Exception;

    @Operation(desc = "Fill in application revision configuration with local configuration values")
    void fillInRevisionConfigurationWithLocalValues(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
            String applicationVersionRevision,
            @Parameter(name = "configId", desc = "Configuration Id") String configId
    ) throws Exception;

    @Operation(desc = "Save application revision configuration changes")
    void saveRevisionConfiguration(
            @Parameter(name = "storage", desc = "Name of the storage") String storage,
            @Parameter(name = "applicationName", desc = "Name of the application") String applicationName,
            @Parameter(name = "applicationVersion", desc = "Version of the application") String applicationVersion,
            @Parameter(name = "applicationVersionRevision", desc = "Revision of the application version")
                        String applicationVersionRevision,
            @Parameter(name = "configId", desc = "Configuration Id") String configId,
            @Parameter(name = "properties", desc = "Map of changed properties") Map<String, Object> properties
    ) throws Exception;

}
