package seedu.task.logic.parser;

import static seedu.task.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.task.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.task.logic.commands.AddCommand;
import seedu.task.logic.commands.CheckCommand;
import seedu.task.logic.commands.ClearCommand;
import seedu.task.logic.commands.Command;
import seedu.task.logic.commands.DeleteCommand;
import seedu.task.logic.commands.EditCommand;
import seedu.task.logic.commands.ExitCommand;
import seedu.task.logic.commands.FindCommand;
import seedu.task.logic.commands.HelpCommand;
import seedu.task.logic.commands.IncorrectCommand;
import seedu.task.logic.commands.ListCommand;
import seedu.task.logic.commands.SelectCommand;
import seedu.task.logic.commands.UncheckCommand;
import seedu.task.logic.commands.UndoCommand;
import seedu.task.model.UndoManager;

/**
 * Parses user input.
 */
public class Parser {

    /**
     * Used for initial separation of command word and args.
     */
    private static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");

    /**
     * Parses user input into command for execution.
     *
     * @param userInput full user input string
     * @return the command based on the user input
     */
    public Command parseCommand(String userInput) {
        final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim());
        if (!matcher.matches()) {
            return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
        }

        final String commandWord = matcher.group("commandWord");
        final String arguments = matcher.group("arguments");
        switch (commandWord) {

        case AddCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Add");
            return new AddCommandParser().parse(arguments);

        case EditCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Edit");
            return new EditCommandParser().parse(arguments);

        case SelectCommand.COMMAND_WORD:
            return new SelectCommandParser().parse(arguments);

        case DeleteCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Delete");
            return new DeleteCommandParser().parse(arguments);

        case ClearCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Clear");
            return new ClearCommand();

        case FindCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Find");
            return new FindCommandParser().parse(arguments);

        case ListCommand.COMMAND_WORD:
<<<<<<< HEAD
        	UndoManager.pushCommand("List");
            return new ListCommand();
=======
            return new ListCommandParser().parse(arguments);
>>>>>>> 18b308c1c2c17ff40d1539dcb728be72545a538b

        case ExitCommand.COMMAND_WORD:
            return new ExitCommand();

        case HelpCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Help");
            return new HelpCommand();

        case CheckCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Check");
            return new CheckedCommandParser().parse(arguments);

        case UncheckCommand.COMMAND_WORD:
        	UndoManager.pushCommand("Uncheck");
            return new UncheckedCommandParser().parse(arguments);

        case UndoCommand.COMMAND_WORD:
        	return new UndoCommand();

        default:
            return new IncorrectCommand(MESSAGE_UNKNOWN_COMMAND);
        }
    }

}

@@ -2649,21 +2649,8 @@
 RD:%0A
-%3C%3C%3C%3C%3C%3C%3C HEAD%0A
     
@@ -2691,54 +2691,8 @@
 %22);%0A
-            return new ListCommand();%0A=======%0A
     
@@ -2751,57 +2751,8 @@
 ts);
-%0A%3E%3E%3E%3E%3E%3E%3E 18b308c1c2c17ff40d1539dcb728be72545a538b
 %0A%0A  

Resolve Conflict