package seedu.address.logic.commands;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.UnmodifiableObservableList;
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.item.Item;
import seedu.address.model.item.Name;
import seedu.address.model.item.ReadOnlyItem;
import seedu.address.model.item.UniquePersonList;
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/NAME" + "\n"
            + "Example: " + COMMAND_WORD + " 1" + " n/buy milk";

    public static final String MESSAGE_EDIT_ITEM_SUCCESS = "Edited Item: %1$s";
    
    public final int targetIndex;
    public final Name newName;

    /*
     * Edits deadline, task, or event by index.
     *      
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public EditCommand(int targetIndex, String name)
            throws IllegalValueException {
        this.targetIndex = targetIndex;
        this.newName = new Name(name);
    }

    @Override
    public CommandResult execute() {

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

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

        ReadOnlyItem itemToEdit = lastShownList.get(targetIndex - 1);
        Item itemToReplace = new Item(itemToEdit);
        itemToReplace.setName(newName);
        
        try {
            model.replaceItem(itemToEdit, itemToReplace);
        } catch (PersonNotFoundException pnfe) {
            assert false : "The target item cannot be missing";
        } catch (UniquePersonList.DuplicatePersonException e) {
            return new CommandResult(MESSAGE_DUPLICATE_ITEM);
        }
        return new CommandResult(String.format(MESSAGE_EDIT_ITEM_SUCCESS, itemToReplace));
    }

}

@@ -32,16 +32,144 @@
 mands;%0A%0A
+import java.util.logging.Logger;%0A%0Aimport seedu.address.commons.core.EventsCenter;%0Aimport seedu.address.commons.core.LogsCenter;%0A
 import s
@@ -371,46 +371,8 @@
 em;%0A
-import seedu.address.model.item.Name;%0A
 impo
@@ -672,16 +672,97 @@
 mmand %7B%0A
+    private static final Logger logger = LogsCenter.getLogger(EditCommand.class);
 %0A    pub
@@ -1254,19 +1254,57 @@
 nal 
-Name newNam
+String newName;%0A    public final String newEndDat
 e;%0A%0A
@@ -1504,16 +1504,84 @@
 ing name
+, String startDate, String startTime, String endDate, String endTime
 )%0A      
@@ -1685,20 +1685,110 @@
  = n
-ew Name(name
+ame;%0A        this.newEndDate = endDate;%0A        logger.info(%22EditCommand object successfully created!%22
 );%0A 
@@ -2277,39 +2277,321 @@
     
-itemToReplace.setName(newName);
+try %7B%0A            if (newName != null) %7B%0A                itemToReplace.setName(newName);%0A            %7D else if (newEndDate != null) %7B%0A                itemToReplace.setEndDate(newEndDate);%0A            %7D%0A        %7D catch (IllegalValueException ive) %7B%0A            return new CommandResult(ive.getMessage());%0A        %7D
 %0A   

Update EditCommand constructor to take all possible fields and support editing of endDate and name