package seedu.address.logic.commands;

//@@author A0125221Y
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();

            case ClearCommand.COMMAND_WORD:
                return undoClear();

            }
        } 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 */


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

    private CommandResult undoClear() {
        assert model != null;
        model.revertData();
        return new CommandResult(UndoCommand.MESSAGE_SUCCESS);
    }

}

@@ -133,24 +133,72 @@
 .task.Task;%0A
+import seedu.address.model.task.UniqueTaskList;%0A
 import seedu
@@ -256,16 +256,16 @@
 eption;%0A
-
 import s
@@ -734,16 +734,159 @@
  found%22;
+%0A    public static final String MESSAGE_FAIL1 = %22testing%22;%0A%0A    private static final String MESSAGE_DUPLICATE_TASK = %22Task is already existed%22;
 %0A%0A    pr
@@ -1339,24 +1339,186 @@
 doClear();%0A%0A
+            case EditCommand.COMMAND_WORD:%0A                try %7B%0A%09%09%09%09%09return undoEdit();%0A%09%09%09%09%7D catch (TaskNotFoundException e) %7B%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%7D%0A%0A
             
@@ -1622,16 +1622,17 @@
 AGE_FAIL
+1
 );%0A%0A    
@@ -2924,24 +2924,24 @@
 vertData();%0A
-
         retu
@@ -2998,10 +2998,864 @@
 %0A    %7D%0A%0A
+    private CommandResult undoEdit() throws TaskNotFoundException %7B%0A        assert model != null;%0A        if (model.getOldTask().isEmpty() && model.getCurrentTask().isEmpty()) %7B%0A            return new CommandResult(String.format(UndoCommand.MESSAGE_FAIL));%0A        %7D else %7B%0A            try %7B%0A                Task toChangeInto = (Task) model.getOldTask().pop();%0A                Task theOriginal = (Task) model.getCurrentTask().pop();%0A                model.updateTask(theOriginal, toChangeInto);%0A                model.getOldNextTask().push(theOriginal);%0A                model.getNewNextTask().push(toChangeInto);%0A            %7D catch (UniqueTaskList.DuplicateTaskException utle) %7B%0A                return new CommandResult(UndoCommand.MESSAGE_DUPLICATE_TASK);%0A            %7D%0A            return new CommandResult(UndoCommand.MESSAGE_SUCCESS);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Update UndoCommand.java