package Visual_DVM_2021.Passes.All;
import Common.Current;
import Common.UI.UI;
import Common.Utils.Utils;
import ProjectData.Project.db_project_info;
import TestingSystem.Common.Test.Test;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;

import java.util.Vector;
public class CreateTestsGroupFromSelectedVersions extends PublishTests {
    @Override
    public String getIconPath() {
        return "/icons/Publish.png";
    }
    @Override
    protected PassCode_2021 getCreateTestCode() {
        return PassCode_2021.CreateTestFromProject;
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = new Vector<>();
        //---
        if (Current.Check(Log, Current.Group)) {
            group = Current.getGroup();
        } else
            return false;
        //---------------------
        Vector<db_project_info> versions = new Vector<>();
        Current.getRoot().getSelectedVersions(versions);
        if (versions.isEmpty()) {
            Log.Writeln_("Не отмечено ни одной версии.");
            return false;
        }
        //---
        Pass_2021 createTestPass = passes.get(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Продолжить");
    }
}
