package seedu.taskboss.logic.commands;

import static seedu.taskboss.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.taskboss.logic.parser.CliSyntax.PREFIX_START_DATE;

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


/**
 * Finds and lists all tasks in TaskBoss whose name contains any of the argument keywords.
 * Keyword matching is case sensitive.
 */
public class FindCommand extends Command {

    public static final String COMMAND_WORD = "find";
    public static final String COMMAND_WORD_SHORT = "f";

    public static final String MESSAGE_USAGE = COMMAND_WORD + "/" + COMMAND_WORD_SHORT
            + ": Finds all tasks whose names contain any of "
            + "the specified keywords (case-sensitive) and displays them as a list with index numbers.\n"
            + "Parameters: n/NAME or sd/STARTDATETIME or ed/ENDDATETIME \n"
            + "Example: " + COMMAND_WORD + " n/meeting" + " || " + COMMAND_WORD_SHORT + " sd/Mar";

    private final String keywords;
    private final String prefix;

    public FindCommand(String pre, String keywords) {
        this.prefix = pre;
        this.keywords = keywords;
    }

    @Override
    public CommandResult execute() {
        if (prefix.equals(PREFIX_NAME.toString())) {
            String[] keywordsList = keywords.split("\\s+");
            final Set<String> keywordSet = new HashSet<String>(Arrays.asList(keywordsList));
            model.updateFilteredTaskListByName(keywordSet);
            return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size()));
        } else if (prefix.equals(PREFIX_START_DATE.toString())) {
            model.updateFilteredTaskListByStartDateTime(keywords);
            return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size()));
        } else {
            model.updateFilteredTaskListByEndDateTime(keywords);
            return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size()));
        }
    }

}

@@ -168,16 +168,85 @@
 RT_DATE;
+%0Aimport static seedu.taskboss.logic.parser.CliSyntax.PREFIX_END_DATE;
 %0A%0Aimport
@@ -739,16 +739,37 @@
 se names
+/information/datetime
  contain
@@ -956,16 +956,33 @@
 ATETIME 
+or i/INFORMATION 
 %5Cn%22%0A    
@@ -1951,16 +1951,62 @@
  %7D else 
+if (prefix.equals(PREFIX_END_DATE.toString()))
 %7B%0A      
@@ -2165,32 +2165,426 @@
 ist().size()));%0A
+        %7D else %7B //prefix.equals(PREFIX_INFORMATION.toString()))%0A            String%5B%5D keywordsList = keywords.split(%22%5C%5Cs+%22);%0A            final Set%3CString%3E keywordSet = new HashSet%3CString%3E(Arrays.asList(keywordsList));%0A            model.updateFilteredTaskListByInformation(keywordSet);%0A            return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredTaskList().size()));%0A
         %7D%0A    %7D%0A

add find by information feature in findCommand; update command usage