package seedu.address.logic.commands;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.UnmodifiableObservableList;
import seedu.address.model.item.ReadOnlyItem;
import seedu.address.model.item.UniquePersonList.PersonNotFoundException;

/**
 * Edits an item identified using it's last displayed index from the task manager.
 */
public class EditCommand extends Command {

    public static final String COMMAND_WORD = "edit";

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

    public static final String MESSAGE_EDIT_ITEM_SUCCESS = "Edited Item: %1$s";

    public final int targetIndex;

    /*
     * Deletes deadline, task, or event by index.
     */
    public EditCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }

    @Override
    public CommandResult execute() {

        UnmodifiableObservableList<ReadOnlyItem> lastShownList = model.getFilteredPersonList();

        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
        }

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

        try {
            model.deleteItem(personToDelete);
        } catch (PersonNotFoundException pnfe) {
            assert false : "The target item cannot be missing";
        }

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

}

@@ -163,31 +163,220 @@
 ess.
-model.item.ReadOnlyItem
+commons.exceptions.IllegalValueException;%0Aimport seedu.address.model.item.Item;%0Aimport seedu.address.model.item.Name;%0Aimport seedu.address.model.item.ReadOnlyItem;%0Aimport seedu.address.model.item.UniquePersonList
 ;%0Aim
@@ -856,16 +856,32 @@
 integer)
+%22 + %22n/NAME%22 + %22
 %5Cn%22%0A    
@@ -923,16 +923,29 @@
 D + %22 1%22
+ + %22buy milk%22
 ;%0A%0A    p
@@ -1019,16 +1019,20 @@
  %251$s%22;%0A
+    
 %0A    pub
@@ -1057,16 +1057,47 @@
 etIndex;
+%0A    public final Name newName;
 %0A%0A    /*
@@ -1157,49 +1157,190 @@
    *
-/%0A    public EditCommand(int targetIndex)
+      %0A     * @throws IllegalValueException if any of the raw values are invalid%0A     */%0A    public EditCommand(int targetIndex, String name)%0A            throws IllegalValueException
  %7B%0A 
@@ -1374,24 +1374,63 @@
 argetIndex;%0A
+        this.newName = new Name(name);%0A
     %7D%0A%0A    @
@@ -1798,22 +1798,20 @@
 nlyItem 
-person
+item
 ToDelete
@@ -1849,16 +1849,100 @@
 x - 1);%0A
+        Item itemToAdd = new Item(itemToDelete);%0A        itemToAdd.setName(newName);
 %0A       
@@ -1977,22 +1977,20 @@
 eteItem(
-person
+item
 ToDelete
@@ -2107,33 +2107,97 @@
 ing%22;%0A        %7D%0A
+        
 %0A
+        try %7B%0A            model.addItem(itemToAdd);%0A    
         return n
@@ -2258,25 +2258,156 @@
 SS, 
-personToDelete));
+itemToAdd));%0A        %7D catch (UniquePersonList.DuplicatePersonException e) %7B%0A            return new CommandResult(MESSAGE_DUPLICATE_ITEM);%0A        %7D
 %0A   

Update EditCommand to support editing of tasks