package seedu.address.logic.commands;

import seedu.address.model.task.ReadOnlyTask;
import seedu.address.model.task.Task;
import seedu.address.model.task.UniqueTaskList.DuplicateTaskException;
import seedu.address.model.task.UniqueTaskList.TaskNotFoundException;

public class UndoCommand extends Command {

    public static final String COMMAND_WORD = "undo";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Undo a previous add/ delete command"
            + "Example: " + COMMAND_WORD;

    public static final String MESSAGE_SUCCESS = "Previous command has been undo";
    public static final String MESSAGE_FAIL = "No previous command found";

    private String prevCommand;

    @Override
    public CommandResult execute() {

        if (!model.getUndoStack().isEmpty()) {
            prevCommand = model.getUndoStack().pop();

            switch (prevCommand) {

            case AddCommand.COMMAND_WORD:
                return undoAdd();

            case DeleteCommand.COMMAND_WORD:
                return undoDelete();

            }
        } else {
            prevCommand = "";
        }

        return new CommandResult(MESSAGE_FAIL);

    }

    private CommandResult undoAdd() {
        assert model != null;
        if (model.getDeletedStackOfTasksAdd().isEmpty()) {
            return new CommandResult(String.format("Unable to undo"));
        } else {
            try {
                ReadOnlyTask reqTask = model.getDeletedStackOfTasksAdd().pop();
                model.deleteTask(reqTask);
            } catch (TaskNotFoundException tnfe) {
                return new CommandResult(String.format("Unable to undo"));
            }
            return new CommandResult(String.format(UndoCommand.MESSAGE_SUCCESS));
        }
    }

    private CommandResult undoDelete() {
        if (model.getDeletedStackOfTasks().isEmpty() || model.getDeletedStackOfTasksIndex().isEmpty()) {
            return new CommandResult("Unable to undo");
        }

        ReadOnlyTask taskToReAdd = model.getDeletedStackOfTasks()
                .pop(); /** Gets the required task to reAdd */

        /*
         * int idxToReAdd = model.getDeletedStackOfTasksIndex() .pop(); /** Gets
         * the required task index to reAdd
         */

        try {
            model.addTask((Task) taskToReAdd);
        } catch (DuplicateTaskException e) {
            return new CommandResult("Unable to undo");
        }
        return new CommandResult(String.format(UndoCommand.MESSAGE_SUCCESS));
    }

}

@@ -32,16 +32,57 @@
 mands;%0A%0A
+import seedu.address.model.ModelManager;%0A
 import s
@@ -115,24 +115,24 @@
 adOnlyTask;%0A
-
 import seedu
@@ -745,22 +745,8 @@
 d;%0A%0A
-    @Override%0A
     
@@ -1075,16 +1075,113 @@
 elete();
+%0A                %0A            case ClearCommand.COMMAND_WORD:%0A                return undoClear();
 %0A%0A      
@@ -2244,156 +2244,8 @@
 */%0A%0A
-        /*%0A         * int idxToReAdd = model.getDeletedStackOfTasksIndex() .pop(); /** Gets%0A         * the required task index to reAdd%0A         */%0A
 %0A   
@@ -2405,32 +2405,32 @@
 do%22);%0A        %7D%0A
-
         return n
@@ -2496,12 +2496,184 @@
 );%0A    %7D
+%0A    %0A    private CommandResult undoClear() %7B%0A        assert model != null;%0A        model.revertData();%0A        return new CommandResult(UndoCommand.MESSAGE_SUCCESS);%0A    %7D
 %0A%0A%7D%0A

Update UndoCommand.java