package seedu.tache.logic.parser;

import static seedu.tache.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.tache.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.tache.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.tache.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.tache.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.NoSuchElementException;

import seedu.tache.commons.exceptions.IllegalValueException;
import seedu.tache.logic.commands.AddCommand;
import seedu.tache.logic.commands.Command;
import seedu.tache.logic.commands.IncorrectCommand;

/**
 * Parses input arguments and creates a new AddCommand object
 */
public class AddCommandParser {

    /**
     * Parses the given {@code String} of arguments in the context of the AddCommand
     * and returns an AddCommand object for execution.
     */
    public Command parse(String args) {
        ArgumentTokenizer argsTokenizer =
                new ArgumentTokenizer(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
        argsTokenizer.tokenize(args);
        try {
            return new AddCommand(
                    argsTokenizer.getPreamble().get(),
//                    argsTokenizer.getValue(PREFIX_PHONE).get(),
//                    argsTokenizer.getValue(PREFIX_EMAIL).get(),
//                    argsTokenizer.getValue(PREFIX_ADDRESS).get(),
                    ParserUtil.toSet(argsTokenizer.getAllValues(PREFIX_TAG))
            );
        } catch (NoSuchElementException nsee) {
            return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
        } catch (IllegalValueException ive) {
            return new IncorrectCommand(ive.getMessage());
        }
    }

}

@@ -364,48 +364,219 @@
 AG;%0A
-%0Aimport java.util.NoSuchElementException
+import static seedu.tache.logic.parser.CliSyntax.PARAMETER_DELIMITER;%0A%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.NoSuchElementException;%0Aimport java.util.Optional;%0Aimport java.util.Set
 ;%0A%0Ai
@@ -1088,172 +1088,488 @@
     
-ArgumentTokenizer argsTokenizer =%0A                new ArgumentTokenizer(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);%0A        argsTokenizer.tokenize(args
+try %7B%0A            if (ParserUtil.numOfDates(args) == 0 && ParserUtil.numOfTimes(args) == 0)%7B%0A                return parseFloatingTask(args);%0A            %7D else %7B%0A                return parseTask(args);%0A            %7D%0A        %7D catch (NoSuchElementException nsee) %7B%0A            return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));%0A        %7D catch (IllegalValueException ive) %7B%0A            return new IncorrectCommand(ive.getMessage()
 );%0A 
@@ -1579,660 +1579,1831 @@
     
-try %7B
+%7D
 %0A    
+%7D%0A
     
+%0A
     
-return new AddCommand(%0A                    argsTokenizer.getPreamble().get(),%0A//                    argsTokenizer.getValue(PREFIX_PHONE).get(),%0A//
+private static Command parseFloatingTask(String args) %0A            throws NoSuchElementException, IllegalValueException%7B%0A        String%5B%5D taskFields = args.split(PARAMETER_DELIMITER);%0A        String name = taskFields%5B0%5D;%0A        Set%3CString%3E tagSet = new HashSet%3CString%3E();%0A        for (int i=1;i%3CtaskFields.length;i++)%7B%0A            tagSet.add(taskFields%5Bi%5D);%0A        %7D%0A        return new AddCommand(name, tagSet);%0A
     
+%7D%0A
     
+%0A
     
-        argsTokenizer.getValue(PREFIX_EMAIL).get(),%0A//                    argsTokenizer.getValue(PREFIX_ADDRESS).get(),%0A                    ParserUtil.toSet(argsTokenizer.getAllValues(PREFIX_TAG))%0A            );%0A        %7D catch (NoSuchElementException nsee) %7B%0A            return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));%0A        %7D catch (IllegalValueException ive) %7B%0A            return new IncorrectCommand(ive.getMessage()
+private static Command parseTask(String args) %0A            throws NoSuchElementException, IllegalValueException%7B%0A        String%5B%5D taskFields = args.split(PARAMETER_DELIMITER);%0A        if (taskFields.length %3C 2)%7B%0A            throw new NoSuchElementException();%0A        %7D else %7B%0A            String name = taskFields%5B0%5D;%0A            String startDate = ParserUtil.parseDate(taskFields%5B1%5D);%0A            String startTime = ParserUtil.parseTime(taskFields%5B1%5D);%0A            Optional%3CString%3E endDate = Optional.empty();%0A            Optional%3CString%3E endTime = Optional.empty();%0A            Set%3CString%3E tagSet = new HashSet%3CString%3E();%0A            if (taskFields.length %3E 2)%7B%0A                if (ParserUtil.isValidDate(taskFields%5B2%5D)) %7B%0A                    endDate = Optional.of(ParserUtil.parseDate(taskFields%5B2%5D));%0A                %7D%0A                if (ParserUtil.isValidTime(taskFields%5B2%5D)) %7B%0A                    endTime = Optional.of(ParserUtil.parseTime(taskFields%5B2%5D));%0A                %7D%0A                int tagIndexStart = 2;%0A                if (endDate.isPresent() %7C%7C endTime.isPresent()) %7B%0A                    tagIndexStart = 3;%0A                %7D%0A                for (int i=tagIndexStart;i%3CtaskFields.length;i++) %7B%0A                    tagSet.add(taskFields%5Bi%5D);%0A                %7D%0A            %7D%0A            return new AddCommand(name, startDate, startTime, endDate, endTime, tagSet
 );%0A 

Update AddCommandParser to match AddCommand