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.AddressBook;
import seedu.address.model.tag.Tag;
import seedu.address.model.tag.UniqueTagList;
import seedu.address.model.task.*;
import seedu.address.model.task.UniqueTaskList.TaskNotFoundException;
import seedu.address.model.task.UniqueTaskList.DuplicateTaskException;


import java.util.HashSet;
import java.util.Set;

public class UpdateCommand extends Command {

	public static final String COMMAND_WORD = "update";
    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Update a task in the task list.\n "
            + "Parameters: INDEX (must be a positive integer) NAME \n"
            + "Example: " + COMMAND_WORD
            + " 1 cs2103 t/quiz";
    
  //TODO: o/OPENTIME c/CLOSETIME i/IMPORTANCE t/tag
    public static final String MESSAGE_UPDATE_TASK_SUCCESS = "Updated Task: %1$s"; 
    
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task list";
    
    public final int targetIndex;
    private final Task toUpdate;
    
    public String task_name;
    
    public UpdateCommand(int targetIndex,String name,Set<String> tags)
    		throws IllegalValueException{
    	
        this.targetIndex = targetIndex;
        
        final Set<Tag> tagSet = new HashSet<>();
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }
       
         this.toUpdate = new Task(
                new Name(name),
                //new DateTime(openTime),
                //new DateTime(closeTime),
                //new Boolean(importance),
               new UniqueTagList(tagSet)
        );
        
        
       
    }
    
    @Override
    public CommandResult execute() {

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

        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }
        ReadOnlyTask taskToUpdate = lastShownList.get(targetIndex - 1);
        
		assert model != null;
		try {
			
			
			model.updateTask(taskToUpdate, toUpdate);
			
		} catch (DuplicateTaskException e) {
			return new CommandResult(MESSAGE_DUPLICATE_TASK);
		}catch (TaskNotFoundException pnfe) {
			assert false : "The target task cannot be missing";
		} 
		return new CommandResult(String.format(MESSAGE_UPDATE_TASK_SUCCESS, toUpdate));
        
        
    }
    
	
}

@@ -550,16 +550,60 @@
 l.Set;%0A%0A
+/**%0A * Updates a task in the task list.%0A */%0A
 public c
@@ -640,17 +640,20 @@
 mand %7B%0A%0A
-%09
+    
 public s
@@ -952,60 +952,8 @@
    %0A
-  //TODO: o/OPENTIME c/CLOSETIME i/IMPORTANCE t/tag%0A
     
@@ -1323,15 +1323,9 @@
 ags)
-%0A    %09%09
+ 
 thro
@@ -1349,22 +1349,17 @@
 ception%7B
-%0A    %09
+ 
 %0A       
@@ -1551,25 +1551,24 @@
    %0A        
- 
 this.toUpdat
@@ -1618,135 +1618,8 @@
 ),%0A 
-               //new DateTime(openTime),%0A                //new DateTime(closeTime),%0A                //new Boolean(importance),%0A
     
@@ -1670,34 +1670,8 @@
  );%0A
-        %0A        %0A       %0A
     
@@ -1732,14 +1732,16 @@
 ) %7B%0A
-%0A
+    
     
-%09
 Unmo
@@ -2020,24 +2020,25 @@
 ;%0A        %7D%0A
+%0A
         Read
@@ -2106,18 +2106,24 @@
        %0A
-%09%09
+        
 assert m
@@ -2140,27 +2140,34 @@
 ll;%0A
-%09%09try %7B%0A%09%09%09%0A%09%09%09%0A%09%09%09
+        try %7B%0A            
 mode
@@ -2208,14 +2208,16 @@
 e);%0A
-%09%09%09%0A%09%09
+        
 %7D ca
@@ -2249,19 +2249,28 @@
 on e) %7B%0A
-%09%09%09
+            
 return n
@@ -2311,19 +2311,26 @@
 _TASK);%0A
-%09%09%7D
+        %7D 
 catch (T
@@ -2362,11 +2362,20 @@
 ) %7B%0A
-%09%09%09
+            
 asse
@@ -2426,15 +2426,27 @@
 g%22;%0A
-%09%09%7D %0A%09%09
+        %7D %0A        
 retu
@@ -2529,33 +2529,8 @@
     
-    %0A        %0A    %7D%0A    %0A%09
+%7D
 %0A%7D%0A

Fix code formatting for UpdateCommand.java