package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import Common.Utils.Utils_;
import Common.Visual.UI;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.ProjectData.Project.db_project_info;
import _VisualDVM.Repository.Server.ServerCode;
import _VisualDVM.TestingSystem.Common.Test.Test;

import java.util.Vector;
public class CreateTestsGroupFromSelectedVersions extends PublishTests {
    @Override
    public String getIconPath() {
        return "/Common/icons/Publish.png";
    }
    @Override
    protected PassCode getCreateTestCode() {
        return PassCode.CreateTestFromProject;
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = new Vector<>();
        //---
        if (Global.testingServer.db.groups.getUI().canModifyCurrent(Log)) {
            group = Global.testingServer.db.groups.getUI().getCurrent();
        } else
            return false;
        //---------------------
        Vector<db_project_info> versions = new Vector<>();
        Global.mainModule.getRoot().getSelectedVersions(versions);
        if (versions.isEmpty()) {
            Log.Writeln_("Не отмечено ни одной версии.");
            return false;
        }
        //---
        Pass createTestPass = Global.mainModule.getPass(getCreateTestCode());
        //---
        for (db_project_info version : versions) {
            if (createTestPass.Do(version, group))
                target.add((Test) createTestPass.target);
        }
        //---
        if (target.isEmpty()) {
            Log.Writeln_("Не удалось создать ни одного теста.");
            return false;
        }
        //---
        return UI.Question("В группу " + Utils_.Brackets(group.description) +
                "\nбудет добавлено " + target.size() + " тестов.\nПродолжить") &&
                SendRequest(ServerCode.PublishObjects, null, target);
    }
}
