/*-
 * ~~~~~~licensing~~~~~~
 * artifact-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.core.artifact.installer.builder.impl.cluster;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.entaxy.platform.core.artifact.installer.builder.ClusterInstaller;
import ru.entaxy.platform.core.artifact.installer.builder.impl.AbstractInstaller;

public class DefaultCellarInstaller extends AbstractInstaller<ClusterInstaller, ClusterTypedInstallerHelper>
        implements ClusterInstaller {

    private static final Logger log = LoggerFactory.getLogger(DefaultCellarInstaller.class);

    // protected DeployedArtifact artifact = null;

    protected Set<String> groups;

    // TODO read default group name from config
    protected String defaultGroupName = "default";

    public DefaultCellarInstaller() {

        super();

        /*
        this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BLUEPRINT,
                ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BlueprintInstallerImpl.class);
        this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_BUNDLE,
                ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BundleInstallerImpl.class);
        this.typedInstallerClasses.put(Artifact.ARTIFACT_CATEGORY_JAR,
                ru.entaxy.platform.core.artifact.installer.builder.typed.impl.JarInstallerImpl.class);
        */

        this.typedHelperClasses.put(
                ru.entaxy.platform.core.artifact.installer.builder.typed.BlueprintInstaller.class,
                ClusterCommonBundleInstallerHelper.class);
        this.typedHelperClasses.put(
                ru.entaxy.platform.core.artifact.installer.builder.typed.BundleInstaller.class,
                ClusterCommonBundleInstallerHelper.class);
        this.typedHelperClasses.put(
                ru.entaxy.platform.core.artifact.installer.builder.typed.JarInstaller.class,
                ClusterCommonBundleInstallerHelper.class);

        initGroups();
    }

    @Override
    protected Class<ClusterTypedInstallerHelper> getHelperClass() {
        return ClusterTypedInstallerHelper.class;
    }

    protected void initGroups() {
        groups = new HashSet<>(Arrays.asList(new String[] {this.defaultGroupName}));
    }

    @Override
    protected ClusterTypedInstallerHelper createDefaultHelper() {
        return new ClusterTypedInstallerHelper();
    }

    @Override
    protected void initHelper(ClusterTypedInstallerHelper helper) {
        helper.setGroups(new ArrayList<>(groups));
    }

    @Override
    public ClusterInstaller groups(String... groups) {
        if (groups != null && groups.length > 0)
            this.groups.addAll(Arrays.asList((String[]) groups));
        else
            initGroups();
        return this;
    }


}
