package seedu.typed.logic.commands;

import java.util.Set;

import seedu.typed.commons.exceptions.IllegalValueException;
import seedu.typed.logic.commands.exceptions.CommandException;
import seedu.typed.logic.commands.util.CommandTypeUtil;
import seedu.typed.model.task.Task;
import seedu.typed.model.task.TaskBuilder;
import seedu.typed.model.task.UniqueTaskList;

/**
 * Adds a task to the task manager.
 */
public class AddCommand extends Command {

    public static final String COMMAND_WORD = "add";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task manager. "
            + "Parameters: NAME [by DATE]  [#TAG]...\n" + "Example: " + COMMAND_WORD
            + " buy 5 broccolis by tomorrow #survival #grocery ";

    //public static final String MESSAGE_SUCCESS = "%1$s added";
    public static final String MESSAGE_SUCCESS = "Task Added!";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager";

    private final Task toAdd;

    /**
     * Creates an AddCommand using raw values.
     *
     * @throws IllegalValueException
     *             if any of the raw values are invalid
     */
    public AddCommand(String name, String date, Set<String> tags) throws IllegalValueException {
        this.toAdd = new TaskBuilder()
                .setName(name)
                .setDate(date)
                .setTags(tags)
                .build();
    }

    @Override
    public CommandResult execute() throws CommandException {
        assert model != null;
        assert session != null;
        try {
            this.model.addTask(toAdd);
            this.session.updateUndoRedoStacks(CommandTypeUtil.TYPE_ADD_TASK, 0, toAdd);
            this.session.updateValidCommandsHistory(commandText);
            return new CommandResult(String.format(MESSAGE_SUCCESS));
        } catch (UniqueTaskList.DuplicateTaskException e) {
            throw new CommandException(MESSAGE_DUPLICATE_TASK);
        }
    }

}

@@ -760,10 +760,8 @@
     
-//
 publ
@@ -819,72 +819,8 @@
 d%22;%0A
-    public static final String MESSAGE_SUCCESS = %22Task Added!%22;%0A
     
@@ -1558,32 +1558,86 @@
 addTask(toAdd);%0A
+            String name = toAdd.getName().toString();%0A
             this
@@ -1840,16 +1840,22 @@
 _SUCCESS
+, name
 ));%0A    

change feedback message for AddCommand to include task name