package guitests;

import org.junit.Test;

import seedu.taskmanager.testutil.TestItem;
import seedu.taskmanager.testutil.TestUtil;

import static org.junit.Assert.assertTrue;
import static seedu.taskmanager.commons.core.Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX;
import static seedu.taskmanager.logic.commands.DeleteByIndexCommand.MESSAGE_DELETE_PERSON_SUCCESS;

public class DeleteCommandTest extends TaskManagerGuiTest {

    @Test
    public void delete() {

        //delete the first in the list
        TestItem[] currentList = td.getTypicalItems();
        int targetIndex = 1;
        assertDeleteSuccess(targetIndex, currentList);

        //delete the last in the list
        currentList = TestUtil.removeItemFromList(currentList, targetIndex);
        targetIndex = currentList.length;
        assertDeleteSuccess(targetIndex, currentList);

        //delete from the middle of the list
        currentList = TestUtil.removeItemFromList(currentList, targetIndex);
        targetIndex = currentList.length/2;
        assertDeleteSuccess(targetIndex, currentList);

        //invalid index
        commandBox.runCommand("deleteByIndex " + currentList.length + 1);
        assertResultMessage(MESSAGE_INVALID_ITEM_DISPLAYED_INDEX);

    }

    /**
     * Runs the delete command to delete the person at specified index and confirms the result is correct.
     * @param targetIndexOneIndexed e.g. to delete the first person in the list, 1 should be given as the target index.
     * @param currentList A copy of the current list of persons (before deletion).
     */
    private void assertDeleteSuccess(int targetIndexOneIndexed, final TestItem[] currentList) {
        TestItem personToDelete = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
        TestItem[] expectedRemainder = TestUtil.removeItemFromList(currentList, targetIndexOneIndexed);

        commandBox.runCommand("deleteByIndex " + targetIndexOneIndexed);

        //confirm the list now contains all previous persons except the deleted person
        assertTrue(personListPanel.isListMatching(expectedRemainder));

        //confirm the result message is correct
        assertResultMessage(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
    }

}

@@ -35,17 +35,16 @@
 t.Test;%0A
-%0A
 import s
@@ -203,165 +203,208 @@
 ger.
-commons.core.Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX;%0Aimport static seedu.taskmanager.logic.commands.DeleteByIndexCommand.MESSAGE_DELETE_PERSON_SUCCESS
+logic.commands.DeleteCommand.MESSAGE_DELETE_ITEM_SUCCESS;%0A%0Aimport java.awt.List;%0Aimport java.util.ArrayList;%0A%0Aimport static seedu.taskmanager.commons.core.Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX
 ;%0A%0Ap
@@ -497,24 +497,58 @@
 delete() %7B%0A%0A
+        /* Delete single items */%0A
         //de
@@ -1141,32 +1141,393 @@
  currentList);%0A%0A
+        /* Delete multiple items */%0A        // delete first and last in the list%0A        currentList = TestUtil.removeItemFromList(currentList, targetIndex);%0A        int%5B%5D targetIndexes = %7B2, currentList.length%7D;%0A//        currentList = TestUtil.removeItemsFromList(currentList, targetIndexes);%0A        assertDeleteSuccess(targetIndexes, currentList);%0A        %0A
         //invali
@@ -1571,28 +1571,22 @@
 (%22delete
-ByIndex
  %22 + 
+(
 currentL
@@ -1600,16 +1600,17 @@
 gth + 1)
+)
 ;%0A      
@@ -1670,16 +1670,24 @@
 INDEX);%0A
+        
 %0A    %7D%0A%0A
@@ -2364,15 +2364,8 @@
 lete
-ByIndex
  %22 +
@@ -2447,41 +2447,1519 @@
 ous 
-persons except the deleted person
+items except the deleted item%0A        assertTrue(personListPanel.isListMatching(expectedRemainder));%0A%0A        //confirm the result message is correct%0A        assertResultMessage(String.format(MESSAGE_DELETE_ITEM_SUCCESS, personToDelete));%0A    %7D%0A%0A    /**%0A     * Runs the delete command to delete the person at specified index and confirms the result is correct.%0A     * @param targetIndexOneIndexed e.g. to delete the first person in the list, 1 should be given as the target index.%0A     * @param currentList A copy of the current list of persons (before deletion).%0A     */%0A    private void assertDeleteSuccess(int%5B%5D targetIndexes, final TestItem%5B%5D currentList) %7B%0A        ArrayList%3CTestItem%3E itemsToDelete = new ArrayList%3CTestItem%3E();%0A        for(int index : targetIndexes) %7B%0A            itemsToDelete.add(currentList%5Bindex-1%5D); //-1 because array uses zero indexing%0A        %7D%0A        TestItem%5B%5D expectedRemainder = TestUtil.removeItemsFromList(currentList, targetIndexes);%0A%0A        // format for deleting multiple indexes%0A        StringBuilder targetIndexesStringFormat = new StringBuilder();%0A        for(int i = 0; i %3C targetIndexes.length; i++) %7B%0A            targetIndexesStringFormat.append(String.valueOf(targetIndexes%5Bi%5D));%0A            if(i != (targetIndexes.length - 1)) %7B%0A                targetIndexesStringFormat.append(%22 %22);%0A            %7D%0A        %7D%0A        commandBox.runCommand(%22delete %22 + targetIndexesStringFormat);%0A%0A        //confirm the list now contains all previous items except the deleted items
 %0A   
@@ -4136,14 +4136,12 @@
 ETE_
-PERSON
+ITEM
 _SUC
@@ -4138,38 +4138,37 @@
 E_ITEM_SUCCESS, 
-person
+items
 ToDelete));%0A    

Update DeleteCommandTest