package seedu.Tdoo.logic.commands;

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

/**
 * Selects a task identified using it's last displayed index from the TodoList.
 */
public class DoneCommand extends Command {

    public static final String COMMAND_WORD = "done";

    public static final String MESSAGE_USAGE = COMMAND_WORD
    		+ ": Mark a Todo-task with given index number as done.\n"
            + "Parameters: TASK_TYPE INDEX_NUMBER(must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " todo 1\n"
            + "Example: " + COMMAND_WORD + " event 1\n"
            + "Example: " + COMMAND_WORD + " deadline 1";

    public static final String MESSAGE_DONE_TASK_SUCCESS = "Completed task: %1$s";
    
    public final String dataType;
    public final int targetIndex;
    
    //@@author A0139920A
    public DoneCommand(String dataType, int targetIndex) {
    	this.dataType = dataType;
        this.targetIndex = targetIndex;
    }

    //@@author A0139920A
    @Override
    public CommandResult execute() {
    	
    	UnmodifiableObservableList<ReadOnlyTask> lastShownList = null;
    	switch (dataType) {
    		case "todo":
    			lastShownList = model.getFilteredTodoList();
    			break;
    		case "event":
    			lastShownList = model.getFilteredEventList();
    			break;
    		case "deadline":
    			lastShownList = model.getFilteredDeadlineList();
    	}
        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

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

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

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

}

@@ -1209,15 +1209,12 @@
     
-%09%0A
     
-%09
 Unmo
@@ -1276,17 +1276,20 @@
 ll;%0A    
-%09
+    
 switch (
@@ -1317,33 +1317,36 @@
 e %22todo%22:%0A    %09%09
-%09
+    
 lastShownList = 
@@ -1372,33 +1372,36 @@
 doList();%0A    %09%09
-%09
+    
 break;%0A    %09%09cas
@@ -1409,33 +1409,36 @@
  %22event%22:%0A    %09%09
-%09
+    
 lastShownList = 
@@ -1473,17 +1473,20 @@
 ;%0A    %09%09
-%09
+    
 break;%0A 
@@ -1513,17 +1513,20 @@
 :%0A    %09%09
-%09
+    
 lastShow
@@ -1562,24 +1562,41 @@
 lineList();%0A
+    %09%09    break;%0A
     %09%7D%0A     

fix indentation issue in donecommand class