/*-
 * ~~~~~~licensing~~~~~~
 * artifact-management
 * ==========
 * Copyright (C) 2020 - 2021 EmDev LLC
 * ==========
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ~~~~~~/licensing~~~~~~
 */
package ru.entaxy.platform.core.artifact.installer.builder.impl.cluster;

import java.util.Arrays;
import java.util.List;

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

import ru.entaxy.platform.core.artifact.Artifact;
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 List<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.impl.BlueprintInstallerImpl.class
				, ClusterCommonBundleInstallerHelper.class);
		this.typedHelperClasses.put(ru.entaxy.platform.core.artifact.installer.builder.typed.impl.BundleInstallerImpl.class
				, ClusterCommonBundleInstallerHelper.class);
		this.typedHelperClasses.put(ru.entaxy.platform.core.artifact.installer.builder.typed.impl.JarInstallerImpl.class
				, ClusterCommonBundleInstallerHelper.class);
		
		initGroups();
	}
	
	protected void initGroups() {
		groups = Arrays.asList(new String[] {this.defaultGroupName});
	}
	
	@Override
	protected ClusterTypedInstallerHelper createDefaultHelper() {
		return new ClusterTypedInstallerHelper();
	} 
	
	@Override
	protected void initHelper(ClusterTypedInstallerHelper helper) {
		helper.setGroups(groups);
	}
	
	@Override
	public ClusterInstaller groups(String... groups) {
		if (groups!=null && groups.length>0)
			this.groups.addAll(Arrays.asList((String[])groups));
		else
			initGroups();
		return this;
	}

	
}
