package seedu.jimi.logic.commands;

import java.util.Set;

/**
 * Finds and lists all tasks in Jimi 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 MESSAGE_USAGE = COMMAND_WORD + ": Finds all tasks whose names contain any of "
            + "the specified keywords (case-sensitive) and displays them as a list with index numbers.\n"
            + "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
            + "Example: " + COMMAND_WORD + " add water";

    private final Set<String> keywords;

    public FindCommand() {
        keywords = null;
    }
    
    public FindCommand(Set<String> keywords) {
        this.keywords = keywords;
    }

    @Override
    public CommandResult execute() {
        model.updateFilteredAgendaTaskList(keywords);
        return new CommandResult(getMessageForTaskListShownSummary(model.getFilteredAgendaTaskList().size()));
    }
    
    @Override
    public boolean isValidCommandWord(String commandWord) {
        for (int i = 1; i <= COMMAND_WORD.length(); i++) {
            if (commandWord.equals(COMMAND_WORD.substring(0, i))) {
                return true;
            }
        }
        return false;
    }
}

@@ -913,16 +913,71 @@
 words);%0A
+        model.updateFilteredAgendaEventList(keywords);%0A
         
@@ -1075,16 +1075,76 @@
 ).size()
+%0A                + model.getFilteredAgendaEventList().size()
 ));%0A    

update both lists