package seedu.address.logic.commands;

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

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.tag.Tag;
import seedu.address.model.tag.UniqueTagList;
import seedu.address.model.task.Description;
import seedu.address.model.task.TaskDate;
import seedu.address.model.task.Priority;
import seedu.address.model.task.Task;
import seedu.address.model.task.UniqueTaskList;

/**
 * Adds a person to the address book.
 */
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: TASK_NAME p/PRIORITY_LEVEL sd/DATE ed/DATE [t/TAG]...\n"
            + "Example: " + COMMAND_WORD
            + " Study for midterm p/1 sd/04/03/2017 ed/06/03/2017 t/study t/midterm";

    public static final String MESSAGE_SUCCESS = "New task added: %1$s";
    public static final String MESSAGE_DUPLICATE_PERSON = "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 priority, String startDate, String endDate, Set<String> tags)
            throws IllegalValueException {
        final Set<Tag> tagSet = new HashSet<>();
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }
        this.toAdd = new Task(
                new Description(name),
                new Priority(priority),
                new TaskDate(startDate),
                new TaskDate(endDate),
                new UniqueTagList(tagSet)
        );
    }

    @Override
    public CommandResult execute() throws CommandException {
        assert model != null;
        try {
            model.addTask(toAdd);
            return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
        } catch (UniqueTaskList.DuplicateTaskException e) {
            throw new CommandException(MESSAGE_DUPLICATE_PERSON);
        }

    }

}

@@ -201,32 +201,33 @@
 mmandException;%0A
+%0A
 import seedu.add
@@ -243,13 +243,22 @@
 l.ta
-g.Tag
+sk.Description
 ;%0Aim
@@ -288,23 +288,19 @@
 l.ta
-g.UniqueTagList
+sk.Priority
 ;%0Aim
@@ -322,38 +322,67 @@
 ess.model.ta
-sk.Description
+g.Tag;%0Aimport seedu.address.model.task.Task
 ;%0Aimport see
@@ -446,57 +446,23 @@
 l.ta
-sk.Priority;%0Aimport seedu.address.model.task.Task
+g.UniqueTagList
 ;%0Aim

reorder AddCommand imports