package Visual_DVM_2021.Passes.All;
import Common.Current;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import SapforTestingSystem.SapforTasksPackage.SapforTasksPackage;
import TestingSystem.TasksPackage.TasksPackageState;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.TestingSystemPass;

import java.util.Vector;
public class DeleteSapforTasksPackage extends TestingSystemPass<SapforTasksPackage> {
    @Override
    public String getIconPath() {
        return "/icons/Delete.png";
    }
    @Override
    public String getButtonText() {
        return "";
    }
    @Override
    protected boolean canStart(Object... args) throws Exception {
        if (Current.Check(Log, Current.SapforTasksPackage)) {
            target = Current.getSapforTasksPackage();
            if (!target.state.equals(TasksPackageState.Done) && !target.state.equals(TasksPackageState.Aborted)) {
                Log.Writeln_("Нельзя удалить активный пакет!");
            } else
                return true;
        }
        return false;
    }
    @Override
    protected void ServerAction() throws Exception {
        Vector<SapforTasksPackage> vector = new Vector<>();
        vector.add(target);
        Command(new ServerExchangeUnit_2021(ServerCode.DeleteAccountObjects, Current.getAccount().email, vector));
    }
    @Override
    protected void performDone() throws Exception {
        super.performDone();
        passes.get(PassCode_2021.SynchronizeTestsTasks).Do();
    }
}


/*
    @Override
    protected void performPreparation() throws Exception {
        if (Current.hasUI()&&Current.HasSapforTasksPackage()) {
            UI.getMainWindow().getTestingWindow().RemoveSapforPackageFromComparison();
        }
*/
