package seedu.whatnow.logic.commands;

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

/**
 * Marks a task identified using it's last displayed index from WhatNow as completed.
 */
public class MarkDoneCommand extends Command {
    
    public static final String COMMAND_WORD = "done";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Mark the task identified by the index number used in the last task listing as completed.\n"
            + "Parameters: TODO/SCHEDULE INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " todo 1\n"
            + "Example: " + COMMAND_WORD + " schedule 1";

    public static final String MESSAGE_MARK_TASK_SUCCESS = "Task marked as completed: %1$s";

    public final String taskType;
    public final int targetIndex;

    public MarkDoneCommand(String taskType, int targetIndex) {
        this.taskType = taskType;
        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 taskToMark = lastShownList.get(targetIndex - 1);

        try {
            model.markTask(taskToMark);
        } catch (TaskNotFoundException pnfe) {
            assert false : "The target task cannot be missing";
        }

        return new CommandResult(String.format(MESSAGE_MARK_TASK_SUCCESS, taskToMark));
    }

}

@@ -910,16 +910,86 @@
 : %251$s%22;
+%0A    %0A    private static final String TASK_TYPE_FLOATING = %22floating%22;
 %0A%0A    pu
@@ -1247,17 +1247,16 @@
 ute() %7B%0A
-%0A
         
@@ -1295,16 +1295,94 @@
 nlyTask%3E
+ lastShownList;%0A        if (taskType.equals(TASK_TYPE_FLOATING)) %7B%0A           
  lastSho
@@ -1399,16 +1399,23 @@
 odel.get
+Current
 Filtered
@@ -1425,16 +1425,119 @@
 kList();
+%0A        %7D%0A        else %7B%0A            lastShownList = model.getCurrentFilteredScheduleList();%0A        %7D
 %0A%0A      

Update MarkDoneCommand to support right panel display of non floating tasks