// @@author A0139399J
package seedu.doit.logic.commands;

import seedu.doit.commons.core.Messages;
import seedu.doit.commons.core.UnmodifiableObservableList;
import seedu.doit.logic.commands.exceptions.CommandException;
import seedu.doit.model.item.ReadOnlyTask;
import seedu.doit.model.item.UniqueTaskList;

public class UnmarkCommand extends Command {
    public static final String COMMAND_WORD = "unmark";

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

    public static final String MESSAGE_UNMARK_TASK_SUCCESS = "Unmarked Task: %1$s";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager.";

    public final int filteredTaskListIndex;

    public UnmarkCommand(int filteredTaskListIndex) {
        assert filteredTaskListIndex > 0;
        this.filteredTaskListIndex = filteredTaskListIndex;
    }

    @Override
    public CommandResult execute() throws CommandException {

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

        if (filteredTaskListIndex <= lastShownTaskList.size()) {
            ReadOnlyTask taskToUnmark = lastShownTaskList.get(filteredTaskListIndex - 1);

            try {
                model.unmarkTask(filteredTaskListIndex - 1, taskToUnmark);
            } catch (UniqueTaskList.TaskNotFoundException pnfe) {
                assert false : "The target task cannot be missing";
            } catch (UniqueTaskList.DuplicateTaskException dpe) {
                throw new CommandException(MESSAGE_DUPLICATE_TASK);
            }

            return new CommandResult(String.format(MESSAGE_UNMARK_TASK_SUCCESS, taskToUnmark));
        } else {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }
    }
}

@@ -51,16 +51,61 @@
 mands;%0A%0A
+import seedu.doit.commons.core.EventsCenter;%0A
 import s
@@ -196,16 +196,76 @@
 leList;%0A
+import seedu.doit.commons.events.ui.JumpToListRequestEvent;%0A
 import s
@@ -1326,16 +1326,21 @@
 kList = 
+this.
 model.ge
@@ -1373,16 +1373,21 @@
     if (
+this.
 filtered
@@ -1493,16 +1493,21 @@
 ist.get(
+this.
 filtered
@@ -1561,16 +1561,21 @@
         
+this.
 model.un
@@ -1583,16 +1583,21 @@
 arkTask(
+this.
 filtered
@@ -1908,24 +1908,173 @@
           %7D%0A
+            EventsCenter.getInstance().post(new JumpToListRequestEvent(%0A                    this.model.getFilteredTaskList().indexOf(taskToUnmark)));
 %0A           

Highlight the task after it is unmarked