package jfdi.parser.commandparsers;

import jfdi.logic.commands.ListCommand;
import jfdi.logic.commands.ListCommand.ListType;
import jfdi.logic.interfaces.Command;
import jfdi.parser.Constants.CommandType;
import jfdi.parser.exceptions.InvalidInputException;

/**
 * The ListCommandParser class is used to parse a user input String that
 * resembles a list command. All user inputs for listing tasks must adhere to
 * the following format: {list identifier} {completed | incomplete}. If the
 * {completed | incomplete} field is unspecified, all tasks currently in storage
 * will be displayed.
 *
 * @author Leonard Hio
 *
 */
public class ListCommandParser extends AbstractCommandParser {
    private static ListCommandParser instance;

    private ListCommandParser() {

    }

    public static ListCommandParser getInstance() {
        return instance == null ? instance = new ListCommandParser() : instance;
    }

    @Override
    /**
     * This method parses the user input (representing a list command) and
     * builds the ListCommand object.
     * @param input
     *            the user input String
     * @return the ListCommand object encapsulating the details of the list command.
     */
    public Command build(String input) {
        ListCommand.Builder builder = new ListCommand.Builder();
        ListType listType = null;
        try {
            listType = getListType(input);
        } catch (InvalidInputException e) {
            return createInvalidCommand(CommandType.list, input);
        }
        builder.setListType(listType);
        return builder.build();
    }

    /**
     * This method gets the type of the list, which corresponds to whether the
     * user wishes to list all tasks, or just those that are
     * completed/incomplete.
     *
     * @param input
     *            the list command input
     * @return the ListType specified in the command input
     * @throws InvalidInputException
     *             if no valid ListType is found
     */
    private ListType getListType(String input) throws InvalidInputException {
        input = removeFirstWord(input);
        if (input.isEmpty()) {
            return ListType.ALL;
        } else if (input.matches("(?i)Completed")) {
            return ListType.COMPLETED;
        } else if (input.matches("(?i)Incomplete")) {
            return ListType.INCOMPLETE;
        } else {
            throw new InvalidInputException(input);
        }
    }

}

@@ -464,26 +464,19 @@
 leted %7C 
-incomplete
+all
 %7D. If th
@@ -476,19 +476,16 @@
 . If the
-%0A *
  %7Bcomple
@@ -491,21 +491,17 @@
 eted
- %7C incomplete
+%0A * %7C all
 %7D fi
@@ -520,24 +520,35 @@
 cified, all 
+incomplete 
 tasks curren
@@ -565,16 +565,16 @@
 rage
-%0A *
  will
+%0A *
  be 
@@ -2172,11 +2172,18 @@
 ype.
-ALL
+INCOMPLETE
 ;%0A  
@@ -2314,18 +2314,11 @@
 (?i)
-Incomplete
+All
 %22)) 
@@ -2343,34 +2343,27 @@
 rn ListType.
-INCOMPLETE
+ALL
 ;%0A        %7D 

Change List command parser to make incomplete as default