package com.strategyquant.extend.DatabankActions;

import java.util.ArrayList;

import javax.swing.JOptionPane;

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

import com.strategyquant.lib.app.MainApp;
import com.strategyquant.lib.databank.Databank;
import com.strategyquant.lib.databank.DatabankAction;
import com.strategyquant.lib.databank.DatabanksRegistry;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.settings.SQCoreConst;
import com.strategyquant.lib.utils.SQUtils;

public class MoveToDatabank extends DatabankAction {
	public static final Logger Log = LoggerFactory.getLogger("MoveToDatabank");

	public MoveToDatabank() {
		setName(L.t("Move to databank"));
	}
	
	@Override
	public void execute(Databank databank) {
		try {
			ArrayList<SQResultsGroup> strategyResults = databank.getSelectedResults();
			
			if(strategyResults.isEmpty()) {
				JOptionPane.showMessageDialog(MainApp.getFrame(), 
						L.t("Please select at least one report using checkbox."),
						L.t("Info"),
		    		    JOptionPane.INFORMATION_MESSAGE);	
	
				return;
			}
			
			for(SQResultsGroup result : strategyResults) {
				DatabanksRegistry.get(SQCoreConst.EAA_DATABANK_SIMPLE_STR).add(SQUtils.deepClone(result));
			}
		} catch(Exception e) {
			Log.error("Exc.", e);
			SQUtils.showExceptionDialog(e);
		}
	}

	@Override
	public String getProduct() {
		return SQCoreConst.PRODUCT_ANY;
	}
	
	@Override
	public String[] getAllowedDatabanks() {
		return new String[]{SQCoreConst.MM_SIM_DATABANK, ""};
	}
}
