package commandFactory;

import java.util.ArrayList;

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


public class CommandActionDelete implements CommandAction{	
	@Override
	public void execute(ParsedResult parsedResult){
		UpdateSummaryReport updateSR = UpdateSummaryReport.getInstance();
		updateSR.unhighlightTask();
		History history = History.getInstance();
		
		StorageList.getInstance().getTaskList().remove(parsedResult.getTaskDetails());
		
		ArrayList<Task> displayList = new ArrayList<Task>();
		if(parsedResult.getCommandType().equals(CommandType.REDO)){
			displayList = history.getRedoDisplayHistory().pop();
		}
		else{
			displayList = SummaryReport.getDisplayList();
		}
		history.getUndoTaskHistory().push(parsedResult.getTaskDetails());
		history.getUndoDisplayHistory().push(displayList);
		history.getUndoCommandHistory().push(CommandType.DELETE);
		updateSR.updateForDeleteAndComplete(parsedResult, displayList);
		
		StorageList.getInstance().saveToFile();	
	}

	@Override
	public void undo(ParsedResult parsedResult) {
		UpdateSummaryReport updateSR = UpdateSummaryReport.getInstance();
		History history = History.getInstance();
		
		StorageList.getInstance().getTaskList().add(parsedResult.getTaskDetails());
		history.getRedoTaskHistory().push(parsedResult.getTaskDetails());

		ArrayList<Task> displayList = history.getUndoDisplayHistory().pop();
		updateSR.updateForUndoDeleteAndComplete(parsedResult, displayList);
		displayList = SummaryReport.getDisplayList();
		history.getRedoDisplayHistory().push(displayList);
		history.getRedoCommandHistory().push(CommandType.DELETE);
		updateSR.highlightTask(parsedResult.getTaskDetails().getId());
		
		StorageList.getInstance().saveToFile();	
	}
}

@@ -435,32 +435,57 @@
 %0D%0A%09%09
-updateSR.unhighlight
+ArrayList%3CTask%3E displayList = new ArrayList%3C
 Task
+%3E
 ();%0D
@@ -525,32 +525,67 @@
 nstance();%0D%0A%09%09%0D%0A
+%09%09updateSR.unhighlightTask();%0D%0A%09%09%0D%0A
 %09%09StorageList.ge
@@ -658,64 +658,8 @@
 %09%09%0D%0A
-%09%09ArrayList%3CTask%3E displayList = new ArrayList%3CTask%3E();%0D%0A
 %09%09if
@@ -777,20 +777,16 @@
 ();%0D%0A%09%09%7D
-%0D%0A%09%09
 else%7B%0D%0A%09
@@ -839,16 +839,20 @@
 ;%0D%0A%09%09%7D%0D%0A
+%09%09%0D%0A
 %09%09histor
@@ -1019,32 +1019,36 @@
 dType.DELETE);%0D%0A
+%09%09%0D%0A
 %09%09updateSR.updat
@@ -1277,24 +1277,80 @@
 nstance();%0D%0A
+%09%09ArrayList%3CTask%3E displayList = new ArrayList%3CTask%3E();%0D%0A
 %09%09History hi
@@ -1537,32 +1537,16 @@
 );%0D%0A%0D%0A%09%09
-ArrayList%3CTask%3E 
 displayL
@@ -1662,16 +1662,86 @@
 List);%0D%0A
+%09%09updateSR.highlightTask(parsedResult.getTaskDetails().getId());%0D%0A%09%09%0D%0A
 %09%09displa
@@ -1827,32 +1827,32 @@
 (displayList);%0D%0A
+
 %09%09history.getRed
@@ -1900,74 +1900,8 @@
 );%0D%0A
-%09%09updateSR.highlightTask(parsedResult.getTaskDetails().getId());%0D%0A
 %09%09%0D%0A

refactor delete