package seedu.todo.controllers;

import seedu.todo.models.TodoListDB;
import seedu.todo.ui.UiManager;
import seedu.todo.ui.views.IndexView;

public class UndoController implements Controller {
    
    private static final String MESSAGE_SUCCESS = "Successfully undid last command!\nTo redo, type \"redo\".";
    private static final String MESSAGE_FAILURE = "There is no command to undo!";

    @Override
    public float inputConfidence(String input) {
        return input.startsWith("undo") ? 1 : 0;
    }

    @Override
    public void process(String input) {
        TodoListDB db = TodoListDB.getInstance();
        if (!db.undo()) {
            UiManager.updateConsoleMessage(MESSAGE_FAILURE);
            return;
        }
        db = TodoListDB.getInstance();
        
        // Render
        IndexView view = UiManager.loadView(IndexView.class);
        view.tasks = db.getAllTasks();
        view.events = db.getAllEvents();
        UiManager.renderView(view);
        
        // Update console message
        UiManager.updateConsoleMessage(MESSAGE_SUCCESS);
    }
}

@@ -26,16 +26,128 @@
 llers;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport seedu.todo.commons.exceptions.UnmatchedQuotesException;%0A
 import s
@@ -619,62 +619,781 @@
   %7D%0A
-%0A    @Override%0A    public void process(String input) %7B
+    %0A    private static Map%3CString, String%5B%5D%3E getTokenDefinitions() %7B%0A        Map%3CString, String%5B%5D%3E tokenDefinitions = new HashMap%3CString, String%5B%5D%3E();%0A        tokenDefinitions.put(%22default%22, new String%5B%5D %7B%22undo%22%7D);%0A        return tokenDefinitions;%0A    %7D%0A%0A    @Override%0A    public void process(String input) %7B%0A        %0A        Map%3CString, String%5B%5D%3E parsedResult;%0A        try %7B%0A            parsedResult = Tokenizer.tokenize(getTokenDefinitions(), input);            %0A        %7D catch (UnmatchedQuotesException e) %7B%0A            System.out.println(%22Unmatched quote!%22);%0A            return;%0A        %7D%0A        %0A        int numUndo = 1;%0A        if (parsedResult.get(%22default%22) != null) %7B%0A            numUndo = Integer.parseInt(parsedResult.get(%22default%22)%5B1%5D);%0A        %7D   %0A        
 %0A   

Parse numUndo.