package Visual_DVM_2021.Passes;
import Common.Current;
import Common.Global;
import Common.UI.UI;
import TestingSystem.Common.TestingPackage.TestingPackage;
import TestingSystem.Common.TestingServer;
import TestingSystem.Common.TasksPackageState;
import Visual_DVM_2021.Passes.Server.PublishServerObject;
public abstract class StartTestingPackage<P extends TestingPackage> extends PublishServerObject<TestingServer, P> {
    public StartTestingPackage(Class<P> p_in) {
        super(Global.testingServer, p_in);
    }
    @Override
    protected int getTimeout() {
        return 0;
    }
    @Override
    public String getIconPath() {
        return "/icons/Start.png";
    }
    protected abstract Current getCurrentName();
    @Override
    protected boolean canStart(Object... args) throws Exception {
        if (!Current.getAccount().CheckRegistered(Log)) {
            return false;
        }
        if (Current.Check(Log, getCurrentName())) {
            target = (P) Current.get(getCurrentName());
            //-
            if (!target.state.equals(TasksPackageState.Draft)) {
                Log.Writeln_("Возможно запустить только пакет, готовящийся к публикации!");
                return false;
            }
            if (target.tasksCount == 0) {
                Log.Writeln_("В пакете отсутствуют задачи.");
                return false;
            }
            if (UI.Question("Будет запущено:\n"
                    + target.tasksCount + " задач.\n" +
                    "Продолжить")) {
                target.state = TasksPackageState.Queued;
                return true;
            }
        }
        return false;
    }
}

