package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import Common.Visual.UI;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Passes.PassCode;
import _VisualDVM.ProjectData.Project.db_project_info;

import java.util.Vector;
public class DeleteSelectedVersions extends Pass<Vector<db_project_info>> {
    boolean has_current_project;
    @Override
    public String getButtonText() {
        return "";
    }
    @Override
    public String getIconPath() {
        return "/Common/icons/Delete.png";
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        has_current_project = false;
        target = new Vector<>();
        //------------------------
        if (!Global.versions_multiselection) {
            Log.Writeln_("Нажмите правую клавишу мыши, и перейдите в режим выбора версий.");
            return false;
        }
        if (!Global.mainModule.Check(Log, Current.Root)) {
            return false;
        }
        Vector<db_project_info> allVersions = new Vector<>();
        Global.mainModule.getRoot().getSelectedVersions(allVersions);
        if (allVersions.size() == 0) {
            Log.Writeln_("Не отмечено ни одной версии.");
            return false;
        }
        int q = Global.mainModule.getRoot().getSelectedVersionsForDeletion(target);
        if (Global.mainModule.HasProject()) {
            for (db_project_info version : target) {
                if (Global.mainModule.getProject().Home.getAbsolutePath().startsWith(version.Home.getAbsolutePath())) {
                    has_current_project = true;
                    break;
                }
            }
        }
        return UI.Warning("Удалить " + q + " версий.");
    }
    @Override
    protected void body() throws Exception {
        for (db_project_info version : target)
            Global.mainModule.getPass(PassCode.DeleteVersion).Do(version);
    }
}
