package seedu.ggist.logic.commands;

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

import seedu.ggist.commons.core.Messages;
import seedu.ggist.commons.exceptions.IllegalValueException;
import seedu.ggist.model.tag.Tag;
import seedu.ggist.model.tag.UniqueTagList;
import seedu.ggist.model.task.*;

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

    public static final String COMMAND_WORD = "add";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a floating task"
            + "Parameters: TASK...\n"
            + "Example: " + COMMAND_WORD
            + "buy milk";

    public static final String MESSAGE_SUCCESS = "New %1$s task added: %2$s";
    public static final String MESSAGE_DUPLICATE_TASK = "duplicated tasks found";
    
    private final Task toAdd;
    private String taskType;
    final Set<Tag> tagSet = new HashSet<>();

    /**
     * Constructor for task with start and end times using raw values.
     *
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public AddCommand(String taskName, String date, String startTime, String endTime, Set<String> tags) throws IllegalValueException {      
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }
        this.toAdd = new EventTask(
                new TaskName(taskName),
                new Date(date),
                new Time(startTime),
                new Time(endTime),
                new UniqueTagList(tagSet)
        );
        taskType = "event";
    }
    
    /**
     * Convenience constructor for task with deadline using raw values.
     *
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public AddCommand(String taskName, String date, String endTime, Set<String> tags) throws IllegalValueException {      
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }
        this.toAdd = new DeadlineTask(
                new TaskName(taskName),
                new Date(date),
                new Time(Messages.MESSAGE_NO_START_TIME_SET),
                new Time(endTime),
                new UniqueTagList(tagSet)
        );
        taskType = "deadline";
    }
    
    /**
     * Convenience constructor for task without deadlines using raw values.
     *
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public AddCommand(String taskName, Set<String> tags) throws IllegalValueException {      
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }
        this.toAdd = new FloatingTask(
                new TaskName(taskName),
                new Date(Messages.MESSAGE_NO_DATE_SPECIFIED),
                new Time(Messages.MESSAGE_NO_START_TIME_SET),
                new Time(Messages.MESSAGE_NO_END_TIME_SET),
                new UniqueTagList(tagSet)
        );
        taskType = "floating";
    }

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

}

@@ -616,16 +616,20 @@
  milk%22;%0A
+    
 %0A    pub
@@ -802,44 +802,400 @@
 ate 
-final Task toAdd;%0A    private String
+enum TaskType %7B%0A        FLOATING(%22floating%22), DEADLINE(%22dealine%22), EVENT(%22event%22); %0A        %0A        private final String taskType;%0A        TaskType(String taskType) %7B%0A            this.taskType = taskType;%0A        %7D%0A        %0A        @Override%0A        %0A        public String toString() %7B%0A            return this.taskType;%0A        %7D%0A    %7D%0A    %0A    private final Task toAdd;%0A    private TaskType
  tas
@@ -1898,23 +1898,30 @@
 kType = 
-%22event%22
+TaskType.EVENT
 ;%0A    %7D%0A
@@ -2591,18 +2591,25 @@
 e = 
-%22deadline%22
+TaskType.DEADLINE
 ;%0A  
@@ -3309,26 +3309,33 @@
 kType = 
-%22floating%22
+TaskType.FLOATING
 ;%0A    %7D%0A
@@ -3540,16 +3540,27 @@
 taskType
+.toString()
 , toAdd)

Add enum for AddCommand