package taskDo;

import Parser.ParsedResult;
import commandFactory.CommandAction;
import commandFactory.CommandFactory;
import commandFactory.CommandType;
import commonClasses.StorageList;

public class Executor {

	public Executor() {
		StorageList.getInstance().loadFile();
	}

	public void execute(ParsedResult parsedResult) {
		assert parsedResult != null;

		CommandFactory commandFactory = new CommandFactory();
		CommandType commandType = parsedResult.getCommandType();

		if (commandType.equals(CommandType.UNDO)) {
			CommandAction commandAction = History.getCommandActionHistory().pop();
			Task lastTask = History.getTaskHistory().pop();
			commandAction.undo(lastTask);
			UpdateSummaryReport.update(commandType, lastTask.getDueDate());
			
		} else {
			CommandAction commandAction = commandFactory.getCommandAction(commandType);			
			commandAction.execute(parsedResult);
			if(!commandType.equals(CommandType.DISPLAY)){
				History.getCommandActionHistory().push(commandAction);
			}
			UpdateSummaryReport.update(commandType, parsedResult.getTaskDetails().getDueDate());
		}
		StorageList.getInstance().saveToFile();
	}
}
@@ -326,40 +326,10 @@
 t) %7B
-%0A
 %09%09
-assert parsedResult != null;%0A
 %0A%09%09C
@@ -652,69 +652,160 @@
 %0A%09%09%09
-UpdateSummaryReport.update(commandType, lastTask.getDueDate()
+parsedResult.setTask(lastTask);%0A%0A%09%09%09CategoryList.updateCategoryList(StorageList.getInstance().getTaskList());%0A%09%09%09UpdateSummaryReport.update(parsedResult
 );%0A%09
@@ -1060,90 +1060,124 @@
 %0A%09%09%09
-UpdateSummaryReport.update(commandType, parsedResult.getTaskDetails().getDueDate()
+CategoryList.updateCategoryList(StorageList.getInstance().getTaskList());%0A%09%09%09UpdateSummaryReport.update(parsedResult
 );%0A%09

add update category in executor