package seedu.taskitty.logic.commands;

import seedu.taskitty.commons.exceptions.IllegalValueException;
import seedu.taskitty.model.tag.Tag;
import seedu.taskitty.model.tag.UniqueTagList;
import seedu.taskitty.model.task.*;

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

/**
 * 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 floating task to the address book. "
            + "Parameters: NAME [t/TAG]...\n"
            + "Example: " + COMMAND_WORD
            + " finish CS2103T t/friends t/owesMoney";

    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;

    /**
     * Convenience constructor using raw values.
     *
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public AddCommand(String name, 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 Name(name),
                new UniqueTagList(tagSet)
        );
    }

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

    }

}

@@ -550,16 +550,47 @@
 rs: NAME
+ %5BDATE%5D %5BSTART_TIME%5D %5BEND_TIME%5D
  %5Bt/TAG%5D
@@ -1082,13 +1082,15 @@
 ring
- name
+%5B%5D data
 , Se
@@ -1104,28 +1104,16 @@
 g%3E tags)
-%0A           
  throws 
@@ -1287,115 +1287,1297 @@
     
-this.toAdd = new Task(%0A                new Name(name),%0A                new UniqueTagList(tagSet)%0A        );
+%0A        //Should I create 3 constructors for task instead? To avoid nulls%0A        //But that leads to another problem..?%0A        if (data.length == Task.TASK_COMPONENT_COUNT) %7B%0A            this.toAdd = new Task(%0A                new Name(data%5BTask.TASK_COMPONENT_INDEX_NAME%5D),%0A                null, null, null,%0A                new UniqueTagList(tagSet)%0A            );%0A        %7D else if (data.length == Task.DEADLINE_COMPONENT_COUNT) %7B%0A            this.toAdd = new Task(%0A                new Name(data%5BTask.DEADLINE_COMPONENT_INDEX_NAME%5D),%0A                new TaskDate(data%5BTask.DEADLINE_COMPONENT_INDEX_DATE%5D),%0A                new TaskTime(data%5BTask.DEADLINE_COMPONENT_INDEX_END_TIME%5D),%0A                null,%0A                new UniqueTagList(tagSet)%0A            );%0A        %7D else if (data.length == Task.EVENT_COMPONENT_COUNT) %7B%0A            this.toAdd = new Task(%0A                new Name(data%5BTask.EVENT_COMPONENT_INDEX_NAME%5D),%0A                new TaskDate(data%5BTask.EVENT_COMPONENT_INDEX_DATE%5D),%0A                new TaskTime(data%5BTask.EVENT_COMPONENT_INDEX_START_TIME%5D),%0A                new TaskTime(data%5BTask.EVENT_COMPONENT_INDEX_END_TIME%5D),%0A                new UniqueTagList(tagSet)%0A            );%0A        %7D else %7B%0A            throw new IllegalValueException(MESSAGE_USAGE);%0A        %7D
 %0A   

add event and deadline to addCommand