package tars.logic.commands;

import tars.commons.core.Messages;
import tars.commons.core.UnmodifiableObservableList;
import tars.model.task.ReadOnlyTask;
import tars.model.task.UniqueTaskList.TaskNotFoundException;

/**
 * Deletes a task identified using it's last displayed index from tars.
 */
public class DeleteCommand extends Command {

    public static final String COMMAND_WORD = "delete";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Deletes the task identified by the index number used in the last task listing.\n"
            + "Parameters: INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " 1";

    public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task: %1$s";

    public final int targetIndex;

    public DeleteCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }


    @Override
    public CommandResult execute() {

        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        ReadOnlyTask taskToDelete = lastShownList.get(targetIndex - 1);

        try {
            model.deleteTask(taskToDelete);
        } catch (TaskNotFoundException tnfe) {
            assert false : "The target task cannot be missing";
        }

        return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete));
    }

}

@@ -111,16 +111,108 @@
 leList;%0A
+import tars.commons.exceptions.DuplicateTaskException;%0Aimport tars.model.task.ReadOnlyTask;%0A
 import t
@@ -222,32 +222,24 @@
 .model.task.
-ReadOnly
 Task;%0Aimport
@@ -409,16 +409,24 @@
 extends 
+Undoable
 Command 
@@ -846,41 +846,151 @@
 s%22;%0A
-%0A    public final int targetIndex
+    %0A    public static final String MESSAGE_UNDO = %22Added: %251$s%22;%0A%0A    public final int targetIndex;%0A    %0A    private ReadOnlyTask taskToDelete
 ;%0A%0A 
@@ -1437,29 +1437,16 @@
         
-ReadOnlyTask 
 taskToDe
@@ -1766,12 +1766,382 @@
 );%0A    %7D
+%0A    %0A    @Override%0A    public CommandResult undo() %7B%0A        try %7B%0A            Task taskToAdd = new Task(taskToDelete);%0A            model.addTask(taskToAdd);%0A            return new CommandResult(String.format(MESSAGE_UNDO, taskToAdd));%0A        %7D catch (DuplicateTaskException e) %7B%0A            return new CommandResult(AddCommand.MESSAGE_DUPLICATE_TASK);%0A        %7D%0A    %7D
 %0A%0A%7D%0A

Change DeleteCommand to extends UndoableCommand