package seedu.taskboss.logic.commands;

import java.util.List;

import seedu.taskboss.commons.core.Messages;
import seedu.taskboss.commons.exceptions.IllegalValueException;
import seedu.taskboss.logic.commands.exceptions.CommandException;
import seedu.taskboss.model.category.UniqueCategoryList;
import seedu.taskboss.model.task.ReadOnlyTask;
import seedu.taskboss.model.task.Task;

//@@author A0144904H
public class MarkDoneCommand extends Command {


    public static final String COMMAND_WORD = "mark";
    public static final String COMMAND_WORD_SHORT = "m";


    public static final String MESSAGE_USAGE = COMMAND_WORD + "/" + COMMAND_WORD_SHORT
            + ": marks the task, identified by the index"
            + " the index nnumber used in the last lisitng, as done in TaskBoss once"
            + " the task is completed. "
            + "Parameters: INDEX (must be a positive integer)...\n"
            + "Example: " + COMMAND_WORD
            + " 1" +  "||" + COMMAND_WORD_SHORT + " 1";

    public static final String MESSAGE_MARK_TASK_DONE_SUCCESS = "Task marked done: %1$s";

    private final int filteredTaskListIndex;

    public MarkDoneCommand(int index) {
        this.filteredTaskListIndex = index - 1;
    }

    @Override
    public CommandResult execute() throws CommandException, IllegalValueException {
        List<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (filteredTaskListIndex >= lastShownList.size()) {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        ReadOnlyTask taskToMarkDone = lastShownList.get(filteredTaskListIndex);
        Task taskMarked = new Task(taskToMarkDone.getName(), taskToMarkDone.getPriorityLevel(),
                taskToMarkDone.getStartDateTime(), taskToMarkDone.getEndDateTime(),
                taskToMarkDone.getInformation(), new UniqueCategoryList("Done"));

        model.updateTask(filteredTaskListIndex, taskMarked);

        model.updateFilteredListToShowAll();
        return new CommandResult(String.format(MESSAGE_MARK_TASK_DONE_SUCCESS, taskToMarkDone));
    }

}

@@ -445,17 +445,16 @@
 mand %7B%0A%0A
-%0A
     publ
@@ -557,17 +557,16 @@
 = %22m%22;%0A%0A
-%0A
     publ
@@ -661,17 +661,17 @@
    + %22: 
-m
+M
 arks the
@@ -675,17 +675,16 @@
 the task
-,
  identif
@@ -721,19 +721,8 @@
 + %22 
-the index n
 numb
@@ -748,21 +748,20 @@
  lis
-i
 t
+i
 ng
-,
  as done
  in 
@@ -760,64 +760,8 @@
 done
- in TaskBoss once%22%0A            + %22 the task is completed
 . %22%0A
@@ -825,11 +825,8 @@
 ger)
-...
 %5Cn%22%0A
@@ -893,10 +893,12 @@
 +  %22
+ 
 %7C%7C
+ 
 %22 + 

Update MarkDoneCommand message usage