package seedu.task.logic;

import javafx.collections.ObservableList;
import seedu.task.commons.core.ComponentManager;
import seedu.task.commons.core.LogsCenter;
import seedu.task.logic.commands.Command;
import seedu.task.logic.commands.CommandResult;
import seedu.task.logic.commands.IncorrectCommand;
import seedu.task.logic.parser.CommandParser;
import seedu.task.model.Model;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.storage.Storage;

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

/**
 * The main LogicManager of the app.
 * @@author A0147335E-reused
 */
public class LogicManager extends ComponentManager implements Logic {
    private final Logger logger = LogsCenter.getLogger(LogicManager.class);

    private final Model model;
    private final CommandParser parser;
    private final HistoryManager historyManager;

    public LogicManager(Model model, Storage storage) {
        this.model = model;
        this.parser = new CommandParser();
        this.historyManager = new HistoryManager();
    }

    @Override
    public CommandResult execute(String commandText) {
        logger.info("----------------[USER COMMAND][" + commandText + "]");
        Command command = parser.parseCommand(commandText);

        command.setData(model);
        command.setHistory(historyManager);

        if (command != null && command instanceof IncorrectCommand) {
            return command.execute(false);
        } else if (command == null && command instanceof IncorrectCommand) {
            return command.execute(false);
        }

        logger.info("SUCCESS");

        if (!commandText.equals("undo")) {
            historyManager.getPreviousCommandList().add(commandText);
            return command.execute(false);
        }
        else {
            return command.execute(true);
        }
    }


    @Override
    public ObservableList<ReadOnlyTask> getFilteredTaskList() {
        return model.getFilteredTaskList();
    }

    @Override
    public ArrayList<RollBackCommand> getUndoList() {
        return historyManager.getUndoList();
    }

    @Override
    public ArrayList<String> getPreviousCommandList() {
        return historyManager.getPreviousCommandList();
    }
}
@@ -1323,25 +1323,24 @@
 nager);%0A
-%0A
         
 if (comm
@@ -1335,31 +1335,60 @@
     
-if (command != null && 
+//@@author%0A        //@@author A0147944U%0A        if (
 comm
@@ -1478,129 +1478,63 @@
    %7D
- else if (command == null && command instanceof IncorrectCommand) %7B%0A            return command.execute(false);%0A        %7D%0A
+%0A        //@@author%0A        //@@author A0147335E-reused
 %0A   

fix warning