package guitests;

import guitests.guihandles.TaskCardHandle;
import org.junit.Test;
import seedu.flexitrack.logic.commands.AddCommand;
import seedu.flexitrack.logic.commands.UnmarkCommand;
import seedu.flexitrack.commons.core.Messages;
import seedu.flexitrack.testutil.TestTask;
import seedu.flexitrack.testutil.TestUtil;

import static org.junit.Assert.assertTrue;

public class MarkCommandTest extends FlexiTrackGuiTest {

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

        // mark a task
        assertMarkSuccess(1, currentList);
        currentList = TestUtil.markTasksToList(currentList, 1);

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

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

        // un-mark a marked test
        assertUnMarkSuccess(1);
        currentList = TestUtil.markTasksToList(currentList, 1);
        //assertTrue(taskListPanel.isListMatching(currentList));

        // un-mark an unmarked test
        assertUnMarkSuccess(3);
        currentList = TestUtil.markTasksToList(currentList, 3);
        //assertTrue(taskListPanel.isListMatching(currentList));

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

 //   private void assertUnMarkSuccess(int taskToUnMark, TestTask... currentList) {
    private void assertUnMarkSuccess(int taskToUnMark) {
        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 assertMarkSuccess(int taskToMark, TestTask... currentList) {
        commandBox.runCommand(TestTask.getMarkCommand(taskToMark));

        // confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.markTasksToList(currentList, taskToMark);
        assertTrue(taskListPanel.isListMatching(expectedList));
    }

}

@@ -121,32 +121,84 @@
 nds.AddCommand;%0A
+import seedu.flexitrack.logic.commands.MarkCommand;%0A
 import seedu.fle
@@ -1002,32 +1002,34 @@
 INDEX);%0A        
+//
 assertTrue(taskL
@@ -1117,39 +1117,36 @@
       assertMark
-Success
+Fail
 (4, currentList)
@@ -1274,16 +1274,29 @@
 uccess(1
+, currentList
 );%0A     
@@ -1313,33 +1313,35 @@
 List = TestUtil.
-m
+unM
 arkTasksToList(c
@@ -1482,17 +1482,27 @@
 Mark
-Success(3
+Fail(3, currentList
 );%0A 
@@ -1523,33 +1523,35 @@
 List = TestUtil.
-m
+unM
 arkTasksToList(c
@@ -1888,16 +1888,446 @@
     %7D%0A%0A 
+private void assertMarkFail(int taskToMark, TestTask... currentList) %7B%0A     commandBox.runCommand(TestTask.getMarkCommand(taskToMark));%0A     assertResultMessage(%22Task already marked!%22);%0A     %0A     // confirm the list now contains all previous tasks plus the new task%0A     //TestTask%5B%5D expectedList = TestUtil.markTasksToList(currentList, taskToMark);%0A     //assertTrue(taskListPanel.isListMatching(expectedList));%0A        %0A    %7D%0A%0A
 //   pri
@@ -2454,16 +2454,41 @@
 ToUnMark
+, TestTask... currentList
 ) %7B%0A    
@@ -2669,10 +2669,470 @@
    %0A
-/*
+        // confirm the list now contains all previous tasks plus the new task%0A        //TestTask%5B%5D expectedList = TestUtil.unMarkTasksToList(currentList, taskToUnMark);%0A        //assertTrue(taskListPanel.isListMatching(expectedList));%0A    %7D%0A    %0A    private void assertUnMarkFail(int taskToUnMark , TestTask... currentList) %7B%0A        commandBox.runCommand(TestTask.getUnMarkCommand(taskToUnMark));%0A        assertResultMessage(%22Task already unmarked!%22);%0A        %0A
     
@@ -3205,32 +3205,34 @@
 ew task%0A        
+//
 TestTask%5B%5D expec
@@ -3296,32 +3296,34 @@
 nMark);%0A        
+//
 assertTrue(taskL
@@ -3365,18 +3365,16 @@
 t));
-*/
 %0A    %7D%0A%0A
     
@@ -3369,16 +3369,21 @@
 %0A    %7D%0A%0A
+    %0A
     priv
@@ -3516,24 +3516,118 @@
 skToMark));%0A
+        assertResultMessage(String.format(MarkCommand.MESSAGE_MARK_TASK_SUCCESS, taskToMark));
 %0A        // 
@@ -3693,32 +3693,34 @@
 ew task%0A        
+//
 TestTask%5B%5D expec
@@ -3784,24 +3784,26 @@
 k);%0A        
+//
 assertTrue(t

fix mark test