package seedu.stask.logic.commands;

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

import seedu.stask.commons.exceptions.IllegalValueException;

//@@author A0139145E 
/**
 * Lists all persons in the task book to the user.
 */
public class ListCommand extends Command {

    public static final String COMMAND_WORD = "list";
    public static final String COMMAND_ALIAS = "ls";

    public static final String LIST_KEYWORD_ALL = "all";
    public static final String LIST_KEYWORD_OD = "od";
    public static final String LIST_KEYWORD_DONE = "done";
    public static final String LIST_KEYWORDS = LIST_KEYWORD_ALL + "/" + LIST_KEYWORD_OD + "/" + LIST_KEYWORD_DONE;
    public static Set<String> keywordsList = new HashSet<>(Arrays.asList(LIST_KEYWORDS.split("/")));
    
    
    public static final String MESSAGE_LIST_USAGE = COMMAND_WORD + ": Lists the tasks in the address book.\n"
            + "Parameters: list " + LIST_KEYWORDS + "\n"
            + "Example: " + COMMAND_WORD
            + " done";

    public static final String MESSAGE_SUCCESS = "Listed %1$s tasks";

    private final String keyword;

    public ListCommand(String key) throws IllegalValueException{
        
        if (keywordsList.contains(key)) {
            this.keyword = key;
        }
        else {
            throw new IllegalValueException(MESSAGE_LIST_USAGE);
        }
    }

    @Override
    public CommandResult execute() {
        String taskStatus;

        switch (keyword) {
        case LIST_KEYWORD_ALL:
            taskStatus = "all";
            model.updateFilteredListToShowAll();
            break;

        case LIST_KEYWORD_DONE:
            taskStatus = "completed";
            model.updateFilteredTaskListByStatus("DONE");
            break;

        case LIST_KEYWORD_OD:
            taskStatus = "overdue and expired";
            model.updateFilteredTaskListByStatus("OVERDUE", "EXPIRE");
            break;

        default:
            taskStatus = "";
            assert false : "Missing case in switch statement";
            break;
        }

        return new CommandResult(String.format(MESSAGE_SUCCESS, taskStatus));
    }

}

@@ -662,140 +662,79 @@
 _OD 
-+ %22/%22 + LIST_KEYWORD_DONE;%0A    public static Set%3CString%3E keywordsList = new HashSet%3C%3E(Arrays.asList(LIST_KEYWORDS.split(%22/%22)));%0A    
+%0A                                            + %22/%22 + LIST_KEYWORD_DONE;
 %0A   
@@ -800,16 +800,29 @@
 ND_WORD 
+%0A            
 + %22: Lis
@@ -979,17 +979,16 @@
  done%22;%0A
-%0A
     publ
@@ -1045,24 +1045,158 @@
 1$s tasks%22;%0A
+    %0A    public static Set%3CString%3E keywordsList = new HashSet%3C%3E(Arrays%0A                            .asList(LIST_KEYWORDS.split(%22/%22)));
 %0A    private
@@ -1282,26 +1282,18 @@
 xception
-%7B%0A       
  
+%7B
 %0A       
@@ -1368,24 +1368,16 @@
        %7D
-%0A       
  else %7B%0A
@@ -1536,17 +1536,16 @@
 Status;%0A
-%0A
         
@@ -1592,16 +1592,17 @@
 WORD_ALL
+ 
 :%0A      
@@ -1687,33 +1687,32 @@
          break;%0A
-%0A
         case LIS
@@ -1725,16 +1725,17 @@
 ORD_DONE
+ 
 :%0A      
@@ -1835,33 +1835,32 @@
          break;%0A
-%0A
         case LIS
@@ -1871,16 +1871,17 @@
 YWORD_OD
+ 
 :%0A      
@@ -2012,17 +2012,16 @@
  break;%0A
-%0A
         
@@ -2027,16 +2027,17 @@
  default
+ 
 :%0A      
@@ -2147,25 +2147,24 @@
 ;%0A        %7D%0A
-%0A
         retu
@@ -2235,11 +2235,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Refactor code quality