package linenux.model;

import java.util.ArrayList;
import java.util.Collections;

import linenux.util.ArrayListUtil;
import linenux.util.RemindersListUtil;

/**
 * Contains all outstanding tasks.
 */
public class Schedule {
    private final ArrayList<Task> taskList;

    /**
     * Constructs an empty schedule
     */
    public Schedule() {
        this.taskList = new ArrayList<Task>();
    }

    /**
     * Constructs the schedule with the given data.
     */
    public Schedule(ArrayList<Task> taskList) {
        this.taskList = taskList;
    }

    /**
     * Adds a task to the schedule
     */
    public void addTask(Task task) {
        taskList.add(task);
    }

    /**
     * Delete the specified task.
     * @param task The task to delete.
     */
    public void deleteTask(Task task) {
        this.taskList.remove(task);
    }

    /**
    * View the specific task.
    * @param task The task to view.
    */
    public String viewTask(Task task) {
        ArrayList<Reminder> reminders = task.getReminders();

        StringBuilder builder = new StringBuilder();
        builder.append(task.toString());
        builder.append('\n');
        builder.append(RemindersListUtil.display(reminders));

        return builder.toString();
    }

    /**
     * Clears all tasks from the schedule
     */
    public void clear() {
        taskList.clear();
    }

    /**
     * Returns the list of tasks
     */
    public ArrayList<Task> getTaskList() {
        return this.taskList;
    }

    /**
     * Performs case-insensitive search using keywords.
     * @param keywords Search keywords
     * @return List of {@code Task} matching the keywords.
     */
    public ArrayList<Task> search(String[] keywords) {
        ArrayList<String> keywordsList = new ArrayListUtil.ChainableArrayListUtil<String>(keywords)
                                                          .map(String::toLowerCase)
                                                          .value();

        return new ArrayListUtil.ChainableArrayListUtil<Task>(this.taskList)
                .filter(task -> {
                    ArrayList<String> taskKeywords = new ArrayListUtil.ChainableArrayListUtil<String>(task.getTaskName().split("\\s+"))
                            .map(String::toLowerCase)
                            .value();

                    return !Collections.disjoint(keywordsList, taskKeywords);
                })
                .value();
    }
}

@@ -377,20 +377,16 @@
 rayList%3C
-Task
 %3E();%0A   
@@ -1148,16 +1148,181 @@
 ('%5Cn');%0A
+        builder.append(%22Reminders:%22 + '%5Cn');%0A%0A        if (reminders.size() == 0) %7B%0A            builder.append(%22There are no reminders found!%22);%0A        %7D else %7B%0A    
         
@@ -1374,16 +1374,26 @@
 nders));
+%0A        %7D
 %0A%0A      
@@ -1981,22 +1981,16 @@
 istUtil%3C
-String
 %3E(keywor
@@ -2202,20 +2202,16 @@
 istUtil%3C
-Task
 %3E(this.t
@@ -2347,22 +2347,16 @@
 istUtil%3C
-String
 %3E(task.g

Update display for view