package guitests;

import static org.junit.Assert.assertTrue;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.MarkCommand.MESSAGE_TYPE_BOOKING;

import org.junit.Test;

import edu.emory.mathcs.backport.java.util.Arrays;
import guitests.guihandles.TaskCardHandle;
import seedu.address.logic.commands.MarkCommand;
import seedu.address.testutil.TaskBuilder;
import seedu.address.testutil.TestTask;

//@@author A0105287E
public class MarkCommandTest extends TaskManagerGuiTest {

    @Test
    public void mark_statusSpecified_success() throws Exception {

        String detailsToEdit = "completed";
        int taskManagerIndex = 2;

        TestTask editedTask = new TaskBuilder().withTitle("Complete task 2").withStartTime("10-10-2017 0100")
                .withDeadline("11-11-2017 2300").withLabels("owesMoney", "friends")
                .withStatus(true).build();

        assertMarkSuccess(taskManagerIndex, taskManagerIndex, detailsToEdit, editedTask);
    }

    @Test
    public void mark_missingTaskIndex_failure() {
        commandBox.runCommand("mark completed");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkCommand.MESSAGE_USAGE));
    }

    @Test
    public void mark_missingStatus_failure() {
        commandBox.runCommand("mark 1");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkCommand.MESSAGE_USAGE));
    }

    @Test
    public void mark_completeBooking_failure() {
        //add a booking
        commandBox.runCommand("book Complete booking #friends on 10-10-2017 2pm to 5pm,"
                + " 11-10-2017 2pm to 5pm, 12-10-2017 2pm to 5pm");
        commandBox.runCommand("mark 8 completed");
        assertResultMessage(MESSAGE_TYPE_BOOKING);
    }


    /**
     * Checks whether the edited task has the correct updated details.
     *
     * @param (int filteredTaskListIndex index of task to edit in filtered list
     * @param taskManagerIndex index of task to edit in the task manager.
     *      Must refer to the same task as {@code filteredTaskListIndex}
     * @param status the status to edit the task with as input to the mark command
     * @param editedTask the expected task after editing the task's details
     */
    private void assertMarkSuccess(int filteredTaskListIndex, int taskManagerIndex,
                                    String status, TestTask editedTask) {
        TestTask[] expectedTasksList = td.getTypicalTasks();

        commandBox.runCommand("mark " + filteredTaskListIndex + " " + status);
        System.out.println("details to edit: " + status);
        System.out.println("edited task: " + editedTask);

        // confirm the new card contains the right data
        TaskCardHandle editedCard = taskListPanel.navigateToTask(editedTask.getTitle().title);
        System.out.println("Edited card: " + editedCard);
        assertMatching(editedTask, editedCard);

        // confirm the list now contains all previous tasks plus the task with updated details
        expectedTasksList[taskManagerIndex - 1] = editedTask;
        Arrays.sort(expectedTasksList);
        assertTrue(taskListPanel.isListMatching(expectedTasksList));
        assertResultMessage(String.format(MarkCommand.MESSAGE_MARK_TASK_SUCCESS, editedTask));
    }

}

@@ -215,16 +215,45 @@
 OKING;%0A%0A
+import java.util.ArrayList;%0A%0A
 import o
@@ -323,51 +323,8 @@
 ys;%0A
-import guitests.guihandles.TaskCardHandle;%0A
 impo
@@ -2503,87 +2503,59 @@
 ();%0A
-%0A
+ 
        
- commandBox.runCommand(%22mark %22 + filteredTaskListIndex + %22 %22 + 
+if (%22completed%22.equalsIgnoreCase(
 status)
-;
+) %7B
 %0A   
@@ -2563,519 +2563,690 @@
     
-System.out.println(%22details to edit: %22 + status);%0A        System.out.println(%22edited task: %22 + editedTask);%0A%0A        // confirm the new card contains the right data%0A        TaskCardHandle editedCard = taskListPanel.navigateToTask(editedTask.getTitle().title);%0A        System.out.println(%22Edited card: %22 + editedCard);%0A        assertMatching(editedTask, editedCard);%0A%0A        // confirm the list now contains all previous tasks plus the task with updated details%0A        expectedTasksList%5BtaskManagerIndex - 1%5D =
+    ArrayList%3CInteger%3E intArrayList = new ArrayList%3CInteger%3E();%0A            for (int i = 0; i %3C td.getTypicalTasks().length; i++) %7B%0A                if (!(i == taskManagerIndex - 1)) %7B%0A                    intArrayList.add(i);%0A                %7D%0A            %7D%0A%0A            int%5B%5D arr = new int%5BintArrayList.size()%5D;%0A%0A            for (int i = 0; i %3C intArrayList.size(); i++) %7B%0A                arr%5Bi%5D = intArrayList.get(i);%0A            %7D%0A            expectedTasksList = td.getTasksByIndex(arr);%0A        %7D%0A%0A        commandBox.runCommand(%22mark %22 + filteredTaskListIndex + %22 %22 + status);%0A        System.out.println(%22details to edit: %22 + status);%0A        System.out.println(%22edited task: %22 +
  edi
@@ -3252,16 +3252,17 @@
 itedTask
+)
 ;%0A      

Change mark command test