package seedu.todoList.logic.commands;

import seedu.todoList.commons.exceptions.IllegalValueException;
import seedu.todoList.model.task.*;
import seedu.todoList.model.task.attributes.*;

/**
 * Edit a task identified using it's last displayed index from the TodoList.
 */
public class EditCommand extends Command {

    public static final String COMMAND_WORD = "edit";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Edits information of the task in the task-list.\n"
            + "Parameters: TASK_TYPE INDEX_NUMBER n/TASK_NAME p/PRIORITY\n"
            + "Example: " + COMMAND_WORD + " edit todo 1 n/Assignment 1 p/2\n"
            + "Parameters: TASK_TYPE INDEX_NUMBER n/TASK_NAME d/DATE s/START_TIME e/END_TIME"
            + "Example: " + COMMAND_WORD + " edit event 1 n/Time's birthday party d/25-12-2016 s/1200 e/1600\n"
            + "Parameters: TASK_TYPE INDEX_NUMBER n/TASK_NAME d/DATE e/END_TIME"
            + "Example: " + COMMAND_WORD + " edit deadline 1 n/CS2103 v0.2 d/25-12-2016 e/1400";

    public static final String MESSAGE_EDIT_task_SUCCESS = "Edited task: %1$s";
    public static final String INVALID_VALUE = "Invalid value";
    
    private final Task toEdit;
    
    /**
     * Edit Todo
     * Convenience constructor using raw values.
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public EditCommand(String name, String priority)
            throws IllegalValueException {
        this.toEdit = new Todo(
                new Name(name),
                new Priority(priority)
        );
    }
    
    /**
     * Edit Event
     * Convenience constructor using raw values.
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public EditCommand(String name, String date, String startTime, String endTime)
            throws IllegalValueException {
        this.toEdit = new Event(
                new Name(name),
                new Date(date),
                new StartTime(startTime),
                new EndTime(endTime)
        );
    }
    
    /**
     * Edit Deadline
     * Convenience constructor using raw values.
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public EditCommand(String name, String date, String endTime)
            throws IllegalValueException {
        this.toEdit = new Deadline(
                new Name(name),
                new Date(date),
                new EndTime(endTime)
        );
    }

    @Override
    public CommandResult execute() {
        assert model != null;
        try {
            model.editTask(toEdit);
            return new CommandResult(String.format(MESSAGE_SUCCESS, toEdit));
        } catch (UniqueTaskList.DuplicatetaskException e) {
            return new CommandResult(MESSAGE_DUPLICATE_TASK);
        } catch (IllegalValueException ive) {
        	return new CommandResult(INVALID_VALUE);
        }
    }
}

@@ -1178,24 +1178,58 @@
 alue%22;%0A    %0A
+    public final int targetIndex;%0A
     private 
@@ -1247,16 +1247,16 @@
 toEdit;%0A
-
     %0A   
@@ -1451,24 +1451,51 @@
  String 
-priority
+date, int priority, int targetIndex
 )%0A      
@@ -1523,32 +1523,69 @@
 alueException %7B%0A
+    %09this.targetIndex = targetIndex;%0A
         this.toE
@@ -1624,32 +1624,64 @@
 new Name(name),%0A
+                new Date(date),%0A
                 
@@ -1693,16 +1693,33 @@
 riority(
+Integer.toString(
 priority
@@ -1719,16 +1719,17 @@
 riority)
+)
 %0A       
@@ -1973,32 +1973,49 @@
 , String endTime
+, int targetIndex
 )%0A            th
@@ -2035,32 +2035,69 @@
 alueException %7B%0A
+    %09this.targetIndex = targetIndex;%0A
         this.toE
@@ -2497,24 +2497,41 @@
 ring endTime
+, int targetIndex
 )%0A          
@@ -2559,24 +2559,61 @@
 Exception %7B%0A
+    %09this.targetIndex = targetIndex;%0A
         this
@@ -2850,16 +2850,16 @@
   try %7B%0A
-
         
@@ -2877,16 +2877,29 @@
 ditTask(
+targetIndex, 
 toEdit);

edit command changes