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 task identified using it's last displayed index from the task
 * manager.
 */
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 taskToDelete = lastShownList.get(targetIndex - 1);

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

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

}

@@ -364,20 +364,22 @@
 letes a 
-task
+person
  identif
@@ -427,23 +427,20 @@
 the 
-task%0A * manager
+address book
 .%0A *
@@ -487,17 +487,20 @@
 mand %7B%0A%0A
-%09
+    
 public s
@@ -540,25 +540,28 @@
  %22delete%22;%0A%0A
-%09
+    
 public stati
@@ -604,19 +604,28 @@
 ND_WORD%0A
-%09%09%09
+            
 + %22: Del
@@ -703,19 +703,28 @@
 ing.%5Cn%22%0A
-%09%09%09
+            
 + %22Param
@@ -767,16 +767,28 @@
 eger)%5Cn%22
+%0A           
  + %22Exam
@@ -814,25 +814,28 @@
 RD + %22 1%22;%0A%0A
-%09
+    
 public stati
@@ -902,17 +902,20 @@
 %251$s%22;%0A%0A
-%09
+    
 public f
@@ -937,17 +937,20 @@
 Index;%0A%0A
-%09
+    
 public D
@@ -981,18 +981,24 @@
 ndex) %7B%0A
-%09%09
+        
 this.tar
@@ -1021,21 +1021,28 @@
 tIndex;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A%0A    
 @Overrid
@@ -1043,17 +1043,20 @@
 verride%0A
-%09
+    
 public C
@@ -1105,18 +1105,24 @@
 tion %7B%0A%0A
-%09%09
+        
 Unmodifi
@@ -1201,18 +1201,24 @@
 ist();%0A%0A
-%09%09
+        
 if (last
@@ -1251,19 +1251,28 @@
 ndex) %7B%0A
-%09%09%09
+            
 throw ne
@@ -1338,23 +1338,35 @@
 INDEX);%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 ReadOnly
@@ -1371,20 +1371,22 @@
 lyEvent 
-task
+person
 ToDelete
@@ -1429,19 +1429,34 @@
 );%0A%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 mode
@@ -1469,20 +1469,22 @@
 teEvent(
-task
+person
 ToDelete
@@ -1486,18 +1486,24 @@
 elete);%0A
-%09%09
+        
 %7D catch 
@@ -1538,11 +1538,20 @@
 ) %7B%0A
-%09%09%09
+            
 asse
@@ -1602,15 +1602,27 @@
 g%22;%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 retu
@@ -1685,20 +1685,22 @@
 UCCESS, 
-task
+person
 ToDelete
@@ -1707,9 +1707,12 @@
 ));%0A
-%09
+    
 %7D%0A%0A%7D

Revert "Update name in deleteCommand"