package guitests;

import org.junit.Test;

import seedu.flexitrack.commons.core.Messages;
import seedu.flexitrack.logic.commands.MarkCommand;
import seedu.flexitrack.logic.commands.UnmarkCommand;
import seedu.flexitrack.testutil.TestTask;
import seedu.flexitrack.testutil.TestUtil;

public class MarkCommandTest extends FlexiTrackGuiTest {

    @Test
    public void mark() {
        // mark a task
        TestTask[] currentList = td.getTypicalSortedTasks();
        assertMarkSuccess(4, currentList);
        currentList = TestUtil.markTasksToList(currentList, 4);
        
        
        // mark a floating task
        assertMarkSuccess(1, currentList);
        currentList = TestUtil.markTasksToList(currentList, 1);

        // mark a task with invalid number
        commandBox.runCommand(TestTask.getMarkCommand(100));
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        //assertTrue(taskListPanel.isListMatching(currentList));

        // mark an already marked task
        assertMarkFail(7, currentList);
        currentList = TestUtil.markTasksToList(currentList, 4);

        // un-mark a marked task
        assertUnMarkSuccess(8, currentList);
        currentList = TestUtil.unMarkTasksToList(currentList, 1);
        //assertTrue(taskListPanel.isListMatching(currentList));

        // un-mark an unmarked task
        assertUnMarkFail(3, currentList);
        currentList = TestUtil.unMarkTasksToList(currentList, 3);
        //assertTrue(taskListPanel.isListMatching(currentList));

        // unmark a task with invalid number
        commandBox.runCommand(TestTask.getUnMarkCommand(100));
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        //assertTrue(taskListPanel.isListMatching(currentList));
    }

 private void assertMarkFail(int taskToMark, TestTask... currentList) {
     commandBox.runCommand(TestTask.getMarkCommand(taskToMark));
     assertResultMessage("Task already marked!");
     
     // confirm the list now contains all previous tasks plus the new task
     //TestTask[] expectedList = TestUtil.markTasksToList(currentList, taskToMark);
     //assertTrue(taskListPanel.isListMatching(expectedList));
        
    }

//   private void assertUnMarkSuccess(int taskToUnMark, TestTask... currentList) {
    private void assertUnMarkSuccess(int taskToUnMark, TestTask... currentList) {
        commandBox.runCommand(TestTask.getUnMarkCommand(taskToUnMark));
        assertResultMessage(String.format(UnmarkCommand.MESSAGE_UNMARK_TASK_SUCCESS, taskToUnMark));
        
        // confirm the list now contains all previous tasks plus the new task
        //TestTask[] expectedList = TestUtil.unMarkTasksToList(currentList, taskToUnMark);
        //assertTrue(taskListPanel.isListMatching(expectedList));
    }
    
    private void assertUnMarkFail(int taskToUnMark , TestTask... currentList) {
        commandBox.runCommand(TestTask.getUnMarkCommand(taskToUnMark));
        assertResultMessage("Task already unmarked!");
        
        // confirm the list now contains all previous tasks plus the new task
        //TestTask[] expectedList = TestUtil.unMarkTasksToList(currentList, taskToUnMark);
        //assertTrue(taskListPanel.isListMatching(expectedList));
    }

    
    private void assertMarkSuccess(int taskToMark, TestTask... currentList) {
        commandBox.runCommand(TestTask.getMarkCommand(taskToMark));
        assertResultMessage(String.format(MarkCommand.MESSAGE_MARK_TASK_SUCCESS, taskToMark));
        // confirm the list now contains all previous tasks plus the new task
        //TestTask[] expectedList = TestUtil.markTasksToList(currentList, taskToMark);
        //assertTrue(taskListPanel.isListMatching(expectedList));
    }

}

@@ -1,8 +1,29 @@
+//@@author A0138455Y%0A
 package 
@@ -354,16 +354,77 @@
 iTest %7B%0A
+    TestTask%5B%5D currentList = td.getTypicalSortedTasks();%0A    
 %0A    @Te
@@ -478,24 +478,26 @@
 ask%0A        
+//
 TestTask%5B%5D c
@@ -644,24 +644,29 @@
 st, 4);%0A    
+%7D   %0A
     %0A       
@@ -666,44 +666,145 @@
     
-    %0A        // mark a floating task
+@Test%0A    public void markFloatingTask() %7B%0A        // mark a floating task%0A        //TestTask%5B%5D currentList = td.getTypicalSortedTasks();
 %0A   
@@ -907,16 +907,77 @@
 st, 1);%0A
+    %7D   %0A    %0A    @Test%0A    public void markInvailidIndex() %7B
 %0A       
@@ -1214,25 +1214,85 @@
 List));%0A
-%0A
  
+   %7D   %0A    %0A    @Test%0A    public void markAnMarkedTask() %7B%0A
        
+ 
 // mark 
@@ -1306,32 +1306,91 @@
 ady marked task%0A
+        commandBox.runCommand(TestTask.getMarkCommand(8));%0A
         assertMa
@@ -1400,9 +1400,9 @@
 ail(
-7
+8
 , cu
@@ -1413,32 +1413,34 @@
 tList);%0A        
+//
 currentList = Te
@@ -1483,41 +1483,150 @@
 4);%0A
-%0A        // un-mark a marked task
+    %7D   %0A    %0A    @Test%0A    public void unmark() %7B%0A        // un-mark a marked task%0A        commandBox.runCommand(TestTask.getMarkCommand(8));
 %0A   
@@ -1725,25 +1725,25 @@
 urrentList, 
-1
+8
 );%0A        /
@@ -1790,32 +1790,92 @@
 (currentList));%0A
+    %7D   %0A    %0A    @Test%0A    public void unmarkUndoneTask() %7B
 %0A        // un-m
@@ -2068,16 +2068,78 @@
 List));%0A
+    %7D   %0A    %0A    @Test%0A    public void unmarkInvalidIndex() %7B
 %0A       

update markCommandTest