package seedu.ezdo.logic.commands;

import seedu.ezdo.commons.core.Messages;
import seedu.ezdo.commons.core.UnmodifiableObservableList;
import seedu.ezdo.logic.commands.exceptions.CommandException;
import seedu.ezdo.model.todo.ReadOnlyTask;
import seedu.ezdo.model.todo.Task;
import seedu.ezdo.model.todo.UniqueTaskList.TaskNotFoundException;

/**
 * Marks a task as identified using its last displayed index from ezDo as done
 */
public class DoneCommand extends Command {

    public static final String COMMAND_WORD = "done";
    public static final String SHORT_COMMAND_WORD = "d";

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

    public static final String MESSAGE_DONE_TASK_SUCCESS = "Done task: %1$s";
    public static final String MESSAGE_DONE_LISTED = "Done tasks listed";

    public final int targetIndex;
    public final boolean requestToViewDoneOnly;

    public DoneCommand(int targetIndex) {
        this.targetIndex = targetIndex;
        this.requestToViewDoneOnly = false;
    }

    public DoneCommand() {
        this.targetIndex = 0;
        this.requestToViewDoneOnly = true;
    }


    @Override
    public CommandResult execute() throws CommandException {

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

        if (requestToViewDoneOnly) {
            model.updateFilteredDoneList();
            return new CommandResult(MESSAGE_DONE_LISTED);
        }

        if (lastShownList.size() < targetIndex) {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        Task taskToDone = (Task) lastShownList.get(targetIndex - 1);

        if (taskToDone.getDone()) {
            throw new CommandException(Messages.MESSAGE_WRONG_LIST);
        }

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

        return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, taskToDone));
    }

}

@@ -29,16 +29,45 @@
 mands;%0A%0A
+import java.util.ArrayList;%0A%0A
 import s
@@ -1050,23 +1050,39 @@
    p
-ublic
+rivate
  final 
-int
+ArrayList%3CInteger%3E
  tar
@@ -1089,28 +1089,78 @@
 getIndex
+es
 ;%0A    p
-ublic
+rivate final ArrayList%3CTask%3E tasksToDone;%0A    private
  final b
@@ -1217,23 +1217,34 @@
 and(
-int targetI
+ArrayList%3CInteger%3E i
 ndex
+es
 ) %7B%0A
@@ -1271,22 +1271,44 @@
 ndex
+es
  = 
-targetI
+new ArrayList%3CInteger%3E(i
 ndex
+es)
 ;%0A  
@@ -1349,16 +1349,66 @@
  false;%0A
+        this.tasksToDone = new ArrayList%3CTask%3E();%0A
     %7D%0A%0A 
@@ -1461,12 +1461,17 @@
 ndex
+es
  = 
-0
+null
 ;%0A  
@@ -1511,16 +1511,49 @@
 = true;%0A
+        this.tasksToDone = null;%0A
     %7D%0A%0A%0A

Update DoneCommand constructors and fields