package guitests;

import static seedu.doit.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import org.junit.Test;

import guitests.guihandles.TaskCardHandle;
import seedu.doit.commons.core.Messages;
import seedu.doit.commons.exceptions.IllegalValueException;
import seedu.doit.logic.commands.AddCommand;
import seedu.doit.testutil.TestTask;
import seedu.doit.testutil.TestUtil;
import seedu.doit.testutil.TypicalTestTasks;


public class AddCommandTest extends TaskManagerGuiTest {
    public static final String MESSAGE_PRIORITY_CONSTRAINTS = "Task priority should only be low med high";
    @Test
    public void add() throws IllegalValueException {
        //add one floating task
        TestTask[] currentList = this.td.getTypicalTasks();
        TestTask taskToAdd = TypicalTestTasks.getFloatingTestTask();
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add another task
        taskToAdd = TypicalTestTasks.getDeadlineTestTask();
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add another event
        taskToAdd = TypicalTestTasks.getEventTestTask();
        assertAddSuccess(taskToAdd, currentList);
        currentList = TestUtil.addTasksToList(currentList, taskToAdd);

        //add duplicate floating task
        this.commandBox.runCommand(TypicalTestTasks.getFloatingTestTask().getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertAllPanelsMatch(currentList);

        //add duplicate event
        this.commandBox.runCommand(TypicalTestTasks.getEventTestTask().getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertAllPanelsMatch(currentList);

        //add duplicate task
        this.commandBox.runCommand(TypicalTestTasks.getDeadlineTestTask().getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_TASK);
        assertAllPanelsMatch(currentList);

        //add to empty list
        this.commandBox.runCommand("clear");
        assertAddSuccess(TypicalTestTasks.getFloatingTestTask());

        //invalid command
        this.commandBox.runCommand("adds invalid1");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);

        //invalid start time
        this.commandBox.runCommand("add invalid2 s/kjsdf e/today p/high d/sss");
        assertResultMessage("Invalid Date Format: " + "kjsdf");
        //invalid end time
        this.commandBox.runCommand("add invalid3 e/kjdgf p/high d/sss");
        assertResultMessage("Invalid Date Format: " + "kjdgf");
        //invalid priority
        this.commandBox.runCommand("add invalid4 p/dfjkhd d/sss");
        assertResultMessage(MESSAGE_PRIORITY_CONSTRAINTS);
        //missing description
        this.commandBox.runCommand("add invalid5 e/today p/high");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));



    }

    private void assertAddSuccess(TestTask taskToAdd, TestTask... currentList) {
        this.commandBox.runCommand(taskToAdd.getAddCommand());

        //confirm the new card contains the right data


        if (!taskToAdd.getIsDone() && taskToAdd.isFloatingTask()) {
            TaskCardHandle addedCard = this.floatingTaskListPanel.navigateToTask(taskToAdd.getName().fullName);
            assertMatching(taskToAdd, addedCard);
        } else if (!taskToAdd.getIsDone() && taskToAdd.isEvent()) {
            TaskCardHandle addedCard = this.eventListPanel.navigateToTask(taskToAdd.getName().fullName);
            assertMatching(taskToAdd, addedCard);
        } else if (!taskToAdd.getIsDone() && taskToAdd.isTask()) {
            TaskCardHandle addedCard = this.taskListPanel.navigateToTask(taskToAdd.getName().fullName);
            assertMatching(taskToAdd, addedCard);
        }


        //confirm the list now contains all previous tasks plus the new task
        TestTask[] expectedList = TestUtil.addTasksToList(currentList, taskToAdd);
        assertAllPanelsMatch(expectedList);
    }

}

@@ -16,88 +16,8 @@
 s;%0A%0A
-import static seedu.doit.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;%0A%0A
 impo
@@ -2278,32 +2278,34 @@
 rt time%0A        
+//
 this.commandBox.
@@ -2361,32 +2361,34 @@
 /sss%22);%0A        
+//
 assertResultMess
@@ -2395,41 +2395,46 @@
 age(
-%22Invalid Date Format: %22 + %22kjsdf%22
+StartTimeMESSAGE_STARTTIME_CONSTRAINTS
 );%0A 
@@ -2459,32 +2459,34 @@
 nd time%0A        
+//
 this.commandBox.
@@ -2534,32 +2534,34 @@
 /sss%22);%0A        
+//
 assertResultMess
@@ -2782,32 +2782,34 @@
 cription%0A       
+//
  this.commandBox
@@ -2852,32 +2852,34 @@
 high%22);%0A        
+//
 assertResultMess

Resolve error