package commandFactory;

import java.util.ArrayList;

import parser.ParsedResult;
import commonClasses.StorageList;
import taskDo.History;
import taskDo.Task;
import taskDo.UpdateSummaryReport;

public class CommandActionAdd implements CommandAction{
	@Override
	public void execute(ParsedResult parsedResult){
		ArrayList<Task> taskList = StorageList.getInstance().getTaskList();
		UpdateSummaryReport updateSR = UpdateSummaryReport.getInstance();
		History history = History.getInstance();
		
		taskList.add(parsedResult.getTaskDetails());
		
		history.getUndoTaskHistory().push(parsedResult.getTaskDetails());
		history.getUndoCommandHistory().push(CommandType.ADD);
		
		updateSR.updateByDueDate(parsedResult);
		updateSR.highlightTask(parsedResult.getTaskDetails().getId());
		
		StorageList.getInstance().saveToFile();	
	}

	@Override
	public void undo(ParsedResult parsedResult) {
		ArrayList<Task> taskList = StorageList.getInstance().getTaskList();
		UpdateSummaryReport updateSR = UpdateSummaryReport.getInstance();
		History history = History.getInstance();
		
		updateSR.unhighlightTask();
		
		history.getRedoTaskHistory().push(parsedResult.getTaskDetails());
		history.getRedoCommandHistory().push(CommandType.ADD);
		
		taskList.remove(parsedResult.getTaskDetails());
		
		updateSR.updateByDueDate(parsedResult);
		
		StorageList.getInstance().saveToFile();	
	}
}

@@ -255,16 +255,47 @@
 ction%7B%0D%0A
+%09//@Author Huang Li A0112508R%0D%0A
 %09@Overri
@@ -542,20 +542,19 @@
 %0D%0A%09%09
-taskList.add
+addIntoList
 (par
@@ -566,319 +566,472 @@
 sult
-.getTaskDetails());%0D%0A%09%09%0D%0A%09%09history.getUndoTaskHistory().push(parsedResult.getTaskDetails());%0D%0A%09%09history.getUndoCommandHistory().push(CommandType.ADD);%0D%0A%09%09%0D%0A%09%09updateSR.updateByDueDate(parsedResult);%0D%0A%09%09updateSR.highlightTask(parsedResult.getTaskDetails().getId());%0D%0A%09%09%0D%0A%09%09StorageList.getInstance().saveToFile(
+, taskList);%0D%0A%09%09pushToUndoStacks(parsedResult, history);%0D%0A%09%09displayResult(parsedResult, updateSR);%0D%0A%09%09saveIntoFile();%0D%0A%09%7D%0D%0A%0D%0A%09private void addIntoList(ParsedResult parsedResult, ArrayList%3CTask%3E taskList) %7B%0D%0A%09%09taskList.add(parsedResult.getTaskDetails());%0D%0A%09%7D%0D%0A%0D%0A%09private void pushToUndoStacks(ParsedResult parsedResult, History history) %7B%0D%0A%09%09history.getUndoTaskHistory().push(parsedResult.getTaskDetails());%0D%0A%09%09history.getUndoCommandHistory().push(CommandType.ADD
 );
-%09
 %0D%0A%09%7D
@@ -1288,272 +1288,883 @@
 %0D%0A%09%09
-updateSR.unhighlightTask();%0D%0A%09%09%0D%0A%09%09history.getRedoTaskHistory().push(parsedResult.getTaskDetails());%0D%0A%09%09history.getRedoCommandHistory().push(CommandType.ADD);%0D%0A%09%09%0D%0A%09%09taskList.remove(parsedResult.getTaskDetails());%0D%0A%09%09%0D%0A%09%09updateSR.updateByDueDate(parsedResult);%0D%0A%09%09
+clearHighlight(updateSR);%0D%0A%09%09pushToRedoStacks(parsedResult, history);%0D%0A%09%09removeFromList(parsedResult, taskList);%0D%0A%09%09displayResult(parsedResult, updateSR);%0D%0A%09%09saveIntoFile();%09%0D%0A%09%7D%0D%0A%0D%0A%09private void clearHighlight(UpdateSummaryReport updateSR) %7B%0D%0A%09%09updateSR.unhighlightTask();%0D%0A%09%7D%0D%0A%0D%0A%09private void removeFromList(ParsedResult parsedResult,%0D%0A%09%09%09ArrayList%3CTask%3E taskList) %7B%0D%0A%09%09taskList.remove(parsedResult.getTaskDetails());%0D%0A%09%7D%0D%0A%0D%0A%09private void pushToRedoStacks(ParsedResult parsedResult, History history) %7B%0D%0A%09%09history.getRedoTaskHistory().push(parsedResult.getTaskDetails());%0D%0A%09%09history.getRedoCommandHistory().push(CommandType.ADD);%0D%0A%09%7D%0D%0A%0D%0A%09private void displayResult(ParsedResult parsedResult,%0D%0A%09%09%09UpdateSummaryReport updateSR) %7B%0D%0A%09%09updateSR.updateByDueDate(parsedResult);%0D%0A%09%09updateSR.highlightTask(parsedResult.getTaskDetails().getId());%0D%0A%09%7D%0D%0A%0D%0A%09private void saveIntoFile() %7B
 %0D%0A%09%09
@@ -2198,22 +2198,21 @@
 aveToFile();
-%09
 %0D%0A%09%7D%0D%0A%7D%0D%0A

refactor add, author added