package seedu.emeraldo.logic.commands;

import static seedu.emeraldo.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

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

import seedu.emeraldo.commons.core.Messages;
import seedu.emeraldo.commons.exceptions.IllegalValueException;
import seedu.emeraldo.model.tag.Tag;
import seedu.emeraldo.model.tag.UniqueTagList;

/**
* Edit the tags of a particular task in the task manager.
*/
public class TagCommand extends Command {

    public static final String COMMAND_WORD = "tag";
    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Add/Delete/Clear the tags to/of the task identified by the index number used in the last tasks listing.\n"
            + "Parameters: add/delete/clear INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " add" + " 1" + " #friends";
    
    public static final String MESSAGE_TAG_EDIT_SUCCESS = "Edited task: %1$s";    
    
    private String action;
    private int targetIndex;
    private Tag tag;
    
    
    public TagCommand(String action, String targetIndex, String tag) throws IllegalValueException {
        this.action = action;
        this.targetIndex = Integer.parseInt(targetIndex);
        this.tag = new Tag(tag);
    }
    
    @Override
    public CommandResult execute() {
        
        if (action.equalsIgnoreCase("add")){
            model.addTag(tag);
        }
        else if (action.equalsIgnoreCase("delete")){
            model.deleteTag(tag);
        }
        else if (action.equalsIgnoreCase("clear")){
            model.clearTag();
        }
        else{
            return new CommandResult(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, TagCommand.MESSAGE_USAGE));
        }
       
        return new CommandResult(String.format(MESSAGE_TAG_EDIT_SUCCESS, targetIndex - 1));
    }

}

@@ -211,16 +211,79 @@
 ssages;%0A
+import seedu.emeraldo.commons.core.UnmodifiableObservableList;%0A
 import s
@@ -421,16 +421,102 @@
 TagList;
+%0Aimport seedu.emeraldo.model.task.ReadOnlyTask;%0Aimport seedu.emeraldo.model.task.Task;
 %0A%0A/**%0A* 
@@ -1472,32 +1472,410 @@
 te() %7B%0A        %0A
+        UnmodifiableObservableList%3CReadOnlyTask%3E lastShownList = model.getFilteredTaskList();%0A%0A        if (lastShownList.size() %3C targetIndex) %7B%0A            indicateAttemptToExecuteIncorrectCommand();%0A            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);%0A        %7D%0A%0A        Task taskTagToEdit = (Task) lastShownList.get(targetIndex - 1);%0A        %0A
         if (acti

Add check for targetIndex