package seedu.taskitty.testutil;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import edu.emory.mathcs.backport.java.util.Arrays;
import guitests.guihandles.TaskListPanelHandle;
import seedu.taskitty.commons.core.LogsCenter;
import seedu.taskitty.model.task.Task;

public class TestTaskList {
    private List<TestTask> todoList;
    private List<TestTask> deadlineList;
    private List<TestTask> eventList;
    
    private final Logger logger = LogsCenter.getLogger(TestTaskList.class);
    
    public TestTaskList(TestTask[] taskList) {
        clear();
        splitTaskList(taskList);
    }
    
    public TestTaskList(TestTask[] todoList, TestTask[] deadlineList, TestTask[] eventList) {
        this.todoList = new ArrayList<TestTask>(Arrays.asList(todoList));
        this.deadlineList = new ArrayList<TestTask>(Arrays.asList(deadlineList));
        this.eventList = new ArrayList<TestTask>(Arrays.asList(eventList));
        this.todoList.sort(null);
        this.deadlineList.sort(null);
        this.eventList.sort(null);
    }
    
    private void splitTaskList(TestTask[] taskList) {
        for (TestTask task : taskList) {
            addTaskToList(task);
        }
    }
    
    public void addTaskToList(TestTask task) {
        switch (task.getPeriod().getNumArgs()) {
        
        case Task.TASK_COMPONENT_COUNT :
            todoList.add(task);
            todoList.sort(null);
            break;
            
        case Task.DEADLINE_COMPONENT_COUNT :
            deadlineList.add(task);
            deadlineList.sort(null);
            break;
            
        case Task.EVENT_COMPONENT_COUNT :
            eventList.add(task);
            eventList.sort(null);
            break;
            
        default :
            logger.warning("Task did not fit in any list");
        }
    }
    
    public TestTask getTaskFromList(int index, String category) {
        switch (category) {
        
        case ("d") :
            return deadlineList.get(index);
            
        case ("e") :
            return eventList.get(index);
            
        default :
            return todoList.get(index);
        }
            
    }
    
    public void editTaskFromList(int index, String category, TestTask task) {
        removeTaskFromList(index, category);
        addTaskToList(task);
    }
    
    public void removeTaskFromList(int index, String category) {
        switch (category) {
        
        case ("d") :
            deadlineList.remove(index);
            break;
            
        case ("e") :
            eventList.remove(index);
            break;
            
        default :
            todoList.remove(index);
        }
    }
    
    public int size(String category) {
        switch (category) {
        
        case ("d") :
            return deadlineList.size();
            
        case ("e") :
            return eventList.size();
            
        default :
            return todoList.size();
        }
    }
    
    public void clear() {
        todoList = new ArrayList<TestTask>();
        deadlineList = new ArrayList<TestTask>();
        eventList = new ArrayList<TestTask>();
    }
    
    public TestTaskList copy() {
        return new TestTaskList(todoList.toArray(new TestTask[todoList.size()]),
                deadlineList.toArray(new TestTask[deadlineList.size()]),
                eventList.toArray(new TestTask[eventList.size()]));
    }
    
    public boolean isListMatching(TaskListPanelHandle taskListPanel) {
        return taskListPanel.isTodoListMatching(todoList.toArray(new TestTask[todoList.size()]))
        && taskListPanel.isDeadlineListMatching(deadlineList.toArray(new TestTask[deadlineList.size()]))
        && taskListPanel.isEventListMatching(eventList.toArray(new TestTask[eventList.size()]));
    }

}

@@ -1940,268 +1940,52 @@
     
-switch (category) %7B%0A        %0A        case (%22d%22) :%0A            return deadlineList.get(index);%0A            %0A        case (%22e%22) :%0A            return eventList.get(index);%0A            %0A        default :%0A            return todoList.get(index);%0A        %7D%0A          
+return getCategoryList(category).get(index);
   %0A 
@@ -2234,200 +2234,107 @@
     
-switch (category) %7B%0A        %0A        case (%22d%22) :%0A            deadlineList.remove(index);%0A            break;%0A            %0A        case (%22e%22) :%0A            eventList.remove(index);%0A    
+getCategoryList(category).remove(index);%0A    %7D%0A    %0A    public int size(String category) %7B%0A
         
 brea
@@ -2333,196 +2333,277 @@
     
-b
 re
-ak;%0A            %0A        default :%0A            todoList.remove(index);%0A        %7D%0A    %7D%0A    %0A    public int size(String category) %7B%0A        switch (category) %7B%0A        %0A        case (%22d%22
+turn getCategoryList(category).size();%0A    %7D%0A    %0A    public List%3CTestTask%3E getCategoryList(String category) %7B%0A        switch (category) %7B%0A        %0A        case(Task.TODO_CATEGORY_CHAR) :%0A            return todoList;%0A        %0A        case (Task.DEADLINE_CATEGORY_CHAR
 ) :%0A
@@ -2629,31 +2629,24 @@
 deadlineList
-.size()
 ;%0A          
@@ -2666,11 +2666,32 @@
 se (
-%22e%22
+Task.EVENT_CATEGORY_CHAR
 ) :%0A
@@ -2714,31 +2714,24 @@
 rn eventList
-.size()
 ;%0A          
@@ -2778,23 +2778,16 @@
 todoList
-.size()
 ;%0A      

Add new method getCategoryList in TestTaskList and update other relevant methods