package seedu.task.logic.commands;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.model.YTomorrow;
import seedu.task.model.tag.Tag;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.UniqueTaskList.DuplicateTaskException;

//@@author A0163848R
/**
 * Clears the task manager.
 */
public class ClearCommand extends Command {

    public static final String COMMAND_WORD = "clear";

    public static final String KEYWORD_ALL = "all";
    public static final String KEYWORD_COMPLETE = Tag.TAG_COMPLETE;
    public static final String KEYWORD_PASSED = "passed";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Clears all tasks, "
            + "or only completed tasts if the " + KEYWORD_COMPLETE + " keyword is specified.\n"
            + "Parameters: [keyword]\n"
            + "Keywords : "
            + KEYWORD_ALL
            + ", "
            + KEYWORD_COMPLETE
            + ", "
            + KEYWORD_PASSED
            + "\n"
            + "Example: " + COMMAND_WORD + " completed";

    public static final String MESSAGE_SUCCESS_ALL = "All tasks have been cleared!";
    public static final String MESSAGE_SUCCESS_COMPLETE = "All competed tasks have been cleared!";
    public static final String MESSAGE_SUCCESS_PASSED = "All passed tasks have been cleared!";
    public static final String MESSAGE_FAILURE = "Clear command not given any keywords!\n" + MESSAGE_USAGE;

    private Set<String> keywords;

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

    @Override
    public CommandResult execute() {
        assert model != null;

        if (keywords.contains(KEYWORD_ALL)) {

            model.resetData(new YTomorrow());

            return new CommandResult(MESSAGE_SUCCESS_ALL);
        }

        if (keywords.contains(KEYWORD_COMPLETE)) {

            List<ReadOnlyTask> filtered = new ArrayList<ReadOnlyTask>();
            for (ReadOnlyTask task : model.getTaskManager().getTaskList()) {
                try {
                    if (!task.getTags().contains(new Tag(Tag.TAG_COMPLETE))) {
                        filtered.add(task);
                    }
                } catch (IllegalValueException e) {
                    e.printStackTrace();
                }
            }
            YTomorrow filteredYTomorrow = new YTomorrow();
            try {
                filteredYTomorrow.setTasks(filtered);
            } catch (DuplicateTaskException e) {
                e.printStackTrace();
            }
            model.resetData(filteredYTomorrow);

            return new CommandResult(MESSAGE_SUCCESS_COMPLETE);
        }

        if (keywords.contains(KEYWORD_PASSED)) {

            List<ReadOnlyTask> filtered = new ArrayList<ReadOnlyTask>();
            for (ReadOnlyTask task : model.getTaskManager().getTaskList()) {
                if (!task.hasPassed()) {
                    filtered.add(task);
                }
            }
            YTomorrow filteredYTomorrow = new YTomorrow();
            try {
                filteredYTomorrow.setTasks(filtered);
            } catch (DuplicateTaskException e) {
                e.printStackTrace();
            }
            model.resetData(filteredYTomorrow);

            return new CommandResult(MESSAGE_SUCCESS_PASSED);
        }

        return new CommandResult(MESSAGE_FAILURE);
    }
}

@@ -497,24 +497,49 @@
 = %22clear%22;%0A%0A
+    //@@author A0164466X%0A
     public s
@@ -689,27 +689,81 @@
 ORD_
-PASSED = %22passed%22;%0A
+INCOMPLETE = Tag.TAG_INCOMPLETE;%0A    //@@author%0A%0A    //@@author A0163848R
 %0A   
@@ -1125,22 +1125,26 @@
 KEYWORD_
-PASSED
+INCOMPLETE
 %0A       
@@ -1290,32 +1290,57 @@
 been cleared!%22;%0A
+    //@@author A0164466X%0A
     public stati
@@ -1390,16 +1390,17 @@
 All comp
+l
 eted tas
@@ -1488,12 +1488,17 @@
 All 
-pass
+incomplet
 ed t
@@ -1515,32 +1515,72 @@
 been cleared!%22;%0A
+    //@@author%0A    //@@author A0163848R%0A
     public stati
@@ -2929,22 +2929,26 @@
 KEYWORD_
-PASSED
+INCOMPLETE
 )) %7B%0A%0A  

Add some things to ClearCommand