package jfdi.logic.commands;

import java.util.ArrayList;
import java.util.stream.Collectors;

import jfdi.logic.events.ListDoneEvent;
import jfdi.logic.interfaces.Command;
import jfdi.storage.apis.TaskAttributes;
import jfdi.storage.apis.TaskDb;

/**
 * @author Liu Xinan
 */
public class ListCommand extends Command {

    public enum ListType {
        ALL,
        COMPLETED,
        INCOMPLETE,
        ALIASES,
        OVERDUE,
        UPCOMING
    }

    private ListType listType;

    private ListCommand(Builder builder) {
        this.listType = builder.listType;
    }

    public static class Builder {

        ListType listType;

        public Builder setListType(ListType listType) {
            this.listType = listType;
            return this;
        }

        public ListCommand build() {
            return new ListCommand(this);
        }
    }

    public ListType getListType() {
        return this.listType;
    }

    @Override
    public void execute() {
        ArrayList<TaskAttributes> tasks = new ArrayList<>(TaskDb.getInstance()
            .getAll());
        switch (listType) {
            case ALL:
                break;
            case COMPLETED:
                tasks = tasks.stream().filter(task -> task.isCompleted())
                    .collect(Collectors.toCollection(ArrayList::new));
                break;
            case INCOMPLETE:
                tasks = tasks.stream().filter(task -> !task.isCompleted())
                    .collect(Collectors.toCollection(ArrayList::new));
                break;
            case ALIASES:
                break;
            case OVERDUE:
                // TODO:
                break;
            case UPCOMING:
                // TODO:
                break;
            default:
                break;
        }
        eventBus.post(new ListDoneEvent(listType, tasks));
    }

    @Override
    public void undo() {
        throw new UnsupportedOperationException();
    }

}

@@ -84,24 +84,110 @@
 ollectors;%0A%0A
+import org.ocpsoft.prettytime.shade.edu.emory.mathcs.backport.java.util.Collections;%0A%0A
 import jfdi.
@@ -1730,91 +1730,304 @@
     
-// TODO:%0A                break;%0A            case UPCOMING:%0A                // TODO:
+tasks = new ArrayList%3CTaskAttributes%3E(TaskDb.getInstance().getOverdue());%0A                Collections.sort(tasks);%0A                break;%0A            case UPCOMING:%0A                tasks = new ArrayList%3CTaskAttributes%3E(TaskDb.getInstance().getUpcoming());%0A                Collections.sort(tasks);
 %0A   

Add list overdue/upcoming command