package udo.logic;

import udo.util.Config;

public class Logic {
    private static final String ERR_FORMAT = "Error: %s";
    private static final String ERR_INVALID_CMD_NAME = "Invalid command";
    private static final String ERR_UNSUPPORTED_CMD = "Unsupported command";
    
    private InputParser parser;
    
    private static String status;
    
    public Logic() {
        parser = new InputParser();
        /* TODO:
         * Initialize Storage
         * Initialize and start up passive thread for reminder
         */
    }
    
    /******************************
     * Code for the active logics *
     ******************************/
    
    /**
     * Execute the command given in the command string 
     * @param command the command string
     */
    public void executeCommand(String command) {
        Command parsedCommand = parser.parseCommand(command);
        if (parser.getErrorStatus() != null) {
            // Syntax error
            status = parser.getErrorStatus();
            // TODO: Inform GUI of error status
        }
        
        if (isCommandValid(parsedCommand)) {
        } else {
           // TODO: Inform GUI of error status 
        }
    }

    /**
     * Check the semantics of a parsed command
     * @param parsedCommand
     * @return the command's correctness
     */
    private boolean isCommandValid(Command parsedCommand) {
        if (parsedCommand == null || parsedCommand.commandName == null ||
            parsedCommand.commandName == null) {
            status = formatErrorStr(ERR_INVALID_CMD_NAME);
            return false;
        }
        
        Config.CommandName cmdName = parsedCommand.commandName;
        switch (cmdName) {
            case ADD:
                return isAddCmdValid(parsedCommand); 
            case DELETE:
                return isDeleteCmdValid(parsedCommand);
            case MODIFY:
                return isModifyCmdValid(parsedCommand);
            case DISPLAY:
                return isDisplayCmdValid(parsedCommand);
            default:
                status = formatErrorStr(ERR_UNSUPPORTED_CMD);
                return false;
        }
    }

    private boolean isDisplayCmdValid(Command parsedCommand) {
        // TODO Auto-generated method stub
        return false;
    }

    private boolean isModifyCmdValid(Command parsedCommand) {
        // TODO Auto-generated method stub
        return false;
    }

    private boolean isDeleteCmdValid(Command parsedCommand) {
        // TODO Auto-generated method stub
        return false;
    }

    private boolean isAddCmdValid(Command parsedCommand) {
        // TODO Auto-generated method stub
        return false;
    }

    private String formatErrorStr(String errorInvalidCmdName) {
        return String.format(ERR_FORMAT, errorInvalidCmdName);
    }
}
@@ -13,16 +13,36 @@
 logic;%0A%0A
+import udo.gui.GUI;%0A
 import u
@@ -79,16 +79,42 @@
 Logic %7B%0A
+    private GUI gui;%0A    %0A
     priv
@@ -315,24 +315,163 @@
 mand%22;%0A    %0A
+    private static final String STATUS_ADDED = %22Task: %25s added sucessfully%22;%0A    private static final Integer MAX_STATUS_LENGTH = 40;%0A    %0A
     private 
@@ -551,19 +551,50 @@
 c Logic(
-) %7B
+GUI gui) %7B%0A        this.gui = gui;
 %0A       
@@ -1338,74 +1338,2331 @@
     
-%7D else %7B%0A           // TODO: Inform GUI of error status %0A        %7D
+    switch (parsedCommand.commandName) %7B%0A                case ADD:%0A                    executeAddCommand(parsedCommand);%0A                    break;%0A                case MODIFY:%0A                    executeModifyCommand(parsedCommand);%0A                    break;%0A                case DELETE:%0A                    executeDeleteCommand(parsedCommand);%0A                    break;%0A                case DISPLAY:%0A                    executeDisplayCommand(parsedCommand);%0A                    break;%0A                default:%0A                    status = ERR_UNSUPPORTED_CMD;%0A            %7D%0A            %0A            gui.displayStatus(status);%0A        %7D else %7B%0A           // TODO: Inform GUI of error status %0A        %7D%0A    %7D%0A%0A    private void executeDisplayCommand(Command parsedCommand) %7B%0A        // TODO fill in default values%0A        // TODO fill in data structure and call storage apis%0A        status = getDisplaySucessStatus(parsedCommand);%0A    %7D%0A%0A    private String getDisplaySucessStatus(Command parsedCommand) %7B%0A        // TODO Auto-generated method stub%0A        return %22%22;%0A    %7D%0A%0A    private void executeDeleteCommand(Command parsedCommand) %7B%0A        // TODO fill in default values%0A        // TODO fill in data structure and call storage apis%0A        status = getDeleteSucessStatus(parsedCommand);%0A    %7D%0A%0A    private String getDeleteSucessStatus(Command parsedCommand) %7B%0A        // TODO Auto-generated method stub%0A        return %22%22;%0A    %7D%0A%0A    private void executeModifyCommand(Command parsedCommand) %7B%0A        // TODO fill in default values%0A        // TODO fill in data structure and call storage apis%0A        status = getModifySucessStatus(parsedCommand);%0A    %7D%0A%0A    private String getModifySucessStatus(Command parsedCommand) %7B%0A        // TODO Auto-generated method stub%0A        return %22%22;%0A    %7D%0A%0A    private void executeAddCommand(Command parsedCommand) %7B%0A        // TODO fill in default values%0A        // TODO fill in data structure and call storage apis%0A        status = getAddSucessStatus(parsedCommand);%0A    %7D%0A%0A    private String getAddSucessStatus(Command parsedCommand) %7B%0A        String taskContent = parsedCommand.argStr;%0A%0A        if (taskContent.length() %3E MAX_STATUS_LENGTH) %7B%0A            taskContent = taskContent.substring(0, MAX_STATUS_LENGTH);%0A        %7D%0A%0A        return String.format(STATUS_ADDED, taskContent);
 %0A   

Add status display to logic