package seedu.cmdo.logic.commands;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashSet;
import java.util.Set;

import seedu.cmdo.commons.exceptions.IllegalValueException;
import seedu.cmdo.model.ToDoList;
import seedu.cmdo.model.tag.Tag;
import seedu.cmdo.model.tag.UniqueTagList;
import seedu.cmdo.model.task.Detail;
import seedu.cmdo.model.task.Done;
import seedu.cmdo.model.task.DueByDate;
import seedu.cmdo.model.task.DueByTime;
import seedu.cmdo.model.task.Priority;
import seedu.cmdo.model.task.ReadOnlyTask;
import seedu.cmdo.model.task.Task;
import seedu.cmdo.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 address book. "
            + "Parameters: <details> by/on <date> at <time> /<priority> /<TAG...>\n"
            + "Example: " + COMMAND_WORD
            + " bring dog to the vet on Thursday at noon /high -dog";

    public static final String MESSAGE_SUCCESS = "New task added: %1$s";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the address book";

    private final Task toAdd;

    /**
     * Convenience constructor using raw values.
     *
     * @throws IllegalValueException if any of the raw values are invalid
     */
    public AddCommand(String details,
                      LocalDate dueByDate,
                      LocalTime dueByTime,
                      String priority,
                      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 Detail(details),
                new DueByDate (dueByDate),
                new DueByTime(dueByTime),
                new Priority(priority),
                new UniqueTagList(tagSet)
        );
    }

    public AddCommand(Task toAdd) {
        this.toAdd = toAdd;
    }

    public ReadOnlyTask getTask() {
        return toAdd;
    }

    @Override
    public CommandResult execute() {
        try {
            model.addTask(toAdd);
            return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
        } catch (UniqueTaskList.DuplicateTaskException dpe) {
            return new CommandResult(MESSAGE_DUPLICATE_TASK);
        }
    }

}
@@ -1288,48 +1288,66 @@
  * C
-onvenience constructor using raw values.
+reated an add command for SINGULAR NON-RANGE DATE AND TIME
 %0A   
@@ -1424,16 +1424,50 @@
 invalid%0A
+     * %0A     * @@author A0139661Y%0A
      */%0A
@@ -2085,22 +2085,978 @@
      );%0A
-
     %7D%0A
+    %0A    /**%0A     * Created an add command for RANGE DATE AND TIME%0A     *%0A     * @throws IllegalValueException if any of the raw values are invalid%0A     * %0A     * @@author A0139661Y%0A     */%0A    public AddCommand(String details,%0A                      LocalDate dueByDateStart,%0A                      LocalTime dueByTimeStart,%0A                      LocalDate dueByDateEnd,%0A                      LocalTime dueByTimeEnd,%0A                      String priority,%0A                      Set%3CString%3E tags) throws IllegalValueException %7B%0A        final Set%3CTag%3E tagSet = new HashSet%3C%3E();%0A        for (String tagName : tags) %7B%0A            tagSet.add(new Tag(tagName));%0A        %7D%0A        this.toAdd = new Task(%0A                new Detail(details),%0A                new DueByDate (dueByDateStart, dueByDateEnd),%0A                new DueByTime(dueByTimeStart, dueByTimeEnd),%0A                new Priority(priority),%0A                new UniqueTagList(tagSet)%0A        );%0A    %7D%0A%0A
 %0A    pub

Add command now supports adding ranges of date and time.