package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.Tasks.Task;
import _VisualDVM.Passes.Project.CurrentProjectPass;

import java.util.Vector;
import java.util.stream.Collectors;
public class DeleteDebugResults extends CurrentProjectPass {
    @Override
    protected void showPreparation() throws Exception {
        Global.mainModule.getDb().compilationTasks.ClearUI();
        Global.mainModule.getDb().runTasks.ClearUI();
    }
    @Override
    protected void body() throws Exception {
        Vector<Task> toDelete = Global.mainModule.getDb().compilationTasks.Data.values().stream().filter(task -> task.belongsToProject(target)).collect(Collectors.toCollection(Vector::new));
        Global.mainModule.getDb().runTasks.Data.values().stream().filter(task -> task.belongsToProject(target)).forEach(toDelete::add);
        for (Task task : toDelete) {
            Utils_.forceDeleteWithCheck(task.getLocalWorkspace());
            Global.mainModule.getDb().Delete(task);
        }
    }
    @Override
    protected void showFinish() throws Exception {
        Global.mainModule.getDb().compilationTasks.ShowUI();
        Global.mainModule.getDb().runTasks.ShowUI();
    }
}
