package _VisualDVM.Passes.All;
import Common.Visual.UI;
import _VisualDVM.Global;
import _VisualDVM.Passes.Server.PublishServerObject;
import _VisualDVM.TestingSystem.Common.TestingServer;
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;

import java.io.File;
import java.util.Vector;
public class StartSelectedSAPFORConfigurations extends PublishServerObject<TestingServer, SapforPackage> {
    protected File sapfor = null;
    Vector<SapforConfiguration> configurations;
    //--
    public StartSelectedSAPFORConfigurations() {
        super(Global.testingServer, SapforPackage.class);
    }
    @Override
    public String getIconPath() {
        return "/Common/icons/BlueStart.png";
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        //--
        if (!Global.mainModule.getAccount().CheckRegistered(Log)) {
            return false;
        }
        if (!Global.testingServer.db.serverSapfors.getUI().CheckCurrent(Log)) {
            return false;
        }
        if (!Global.testingServer.db.serverSapfors.getUI().getCurrent().state.equals(ServerSapforState.Done)) {
            Log.Writeln_("Выбранная версия SAPFOR не собрана!");
            return false;
        }
        //--
        if (!Global.testingServer.db.sapforConfigurations.getUI().CheckSelectedOrCurrent(Log)) {
            return false;
        }
        configurations = Global.testingServer.db.sapforConfigurations.getUI().getSelectedOrCurrent();
        target = new SapforPackage(Global.mainModule.getAccount(),
                Global.testingServer.db.serverSapfors.getUI().getCurrent(),
                configurations,
                Global.normalProperties.EmailOnTestingProgress ? 1 : 0,
                Log);
        if (target.tasksCount == 0) {
            Log.Writeln_("Не сформировано ни одной новой задачи.");
            return false;
        }
        return (UI.Question("Будет запущено " + target.tasksCount + " задач. Продолжить"));
    }
}
