package org.teamstbf.yats.logic.commands;

import org.teamstbf.yats.commons.core.Messages;
import org.teamstbf.yats.commons.core.UnmodifiableObservableList;
import org.teamstbf.yats.logic.commands.exceptions.CommandException;
import org.teamstbf.yats.model.item.ReadOnlyEvent;
import org.teamstbf.yats.model.item.UniqueEventList.EventNotFoundException;

/**
 * Deletes a person identified using it's last displayed index from the address book.
 */
public class DeleteCommand extends Command {

    public static final String COMMAND_WORD = "delete";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Deletes the task identified by the index number used in the last task listing.\n"
            + "Parameters: INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " 1";

    public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task: %1$s";

    public final int targetIndex;

    public DeleteCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }


    @Override
    public CommandResult execute() throws CommandException {

        UnmodifiableObservableList<ReadOnlyEvent> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        ReadOnlyEvent personToDelete = lastShownList.get(targetIndex - 1);

        try {
            model.deleteEvent(personToDelete);
        } catch (EventNotFoundException pnfe) {
            assert false : "The target task cannot be missing";
        }

        return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, personToDelete));
    }

}

@@ -364,22 +364,20 @@
 letes a 
-person
+task
  identif
@@ -425,20 +425,23 @@
 the 
-address book
+task%0A * manager
 .%0A *
@@ -488,20 +488,17 @@
 mand %7B%0A%0A
-    
+%09
 public s
@@ -538,28 +538,25 @@
  %22delete%22;%0A%0A
-    
+%09
 public stati
@@ -599,28 +599,19 @@
 ND_WORD%0A
-            
+%09%09%09
 + %22: Del
@@ -689,28 +689,19 @@
 ing.%5Cn%22%0A
-            
+%09%09%09
 + %22Param
@@ -744,28 +744,16 @@
 eger)%5Cn%22
-%0A           
  + %22Exam
@@ -779,28 +779,25 @@
 RD + %22 1%22;%0A%0A
-    
+%09
 public stati
@@ -864,20 +864,17 @@
 %251$s%22;%0A%0A
-    
+%09
 public f
@@ -896,20 +896,17 @@
 Index;%0A%0A
-    
+%09
 public D
@@ -937,24 +937,18 @@
 ndex) %7B%0A
-        
+%09%09
 this.tar
@@ -975,20 +975,13 @@
 ex;%0A
-    %7D%0A%0A%0A    
+%09%7D%0A%0A%09
 @Ove
@@ -986,20 +986,17 @@
 verride%0A
-    
+%09
 public C
@@ -1045,24 +1045,18 @@
 tion %7B%0A%0A
-        
+%09%09
 Unmodifi
@@ -1135,24 +1135,18 @@
 ist();%0A%0A
-        
+%09%09
 if (last
@@ -1179,28 +1179,19 @@
 ndex) %7B%0A
-            
+%09%09%09
 throw ne
@@ -1257,35 +1257,23 @@
 INDEX);%0A
-        %7D%0A%0A        
+%09%09%7D%0A%0A%09%09
 ReadOnly
@@ -1278,22 +1278,20 @@
 lyEvent 
-person
+task
 ToDelete
@@ -1334,34 +1334,19 @@
 );%0A%0A
-        try %7B%0A            
+%09%09try %7B%0A%09%09%09
 mode
@@ -1359,22 +1359,20 @@
 teEvent(
-person
+task
 ToDelete
@@ -1374,24 +1374,18 @@
 elete);%0A
-        
+%09%09
 %7D catch 
@@ -1420,20 +1420,11 @@
 ) %7B%0A
-            
+%09%09%09
 asse
@@ -1475,27 +1475,15 @@
 g%22;%0A
-        %7D%0A%0A        
+%09%09%7D%0A%0A%09%09
 retu
@@ -1550,14 +1550,12 @@
 SS, 
-person
+task
 ToDe
@@ -1566,12 +1566,9 @@
 ));%0A
-    
+%09
 %7D%0A%0A%7D

Update name in deleteCommand