from commands.command_base import AbstractCommand
from enum import Enum
import config as config
import db

import commands.loader as command_loader

import credentials

class Help_Module():
    def __init__(self):
        super().__init__()
        #self.dbCredential: credentials.DB_Credential

    def main(self):
        print("[Help Module]> help test")
        self.isCommandEnabled = True

    def help_command_response(self, command:AbstractCommand, responseType):
        response = help_command_response()
        response.setup(command, responseType)
        response.makeResponse()
        return response

class help_command_responseType(Enum):
    plain = 1 # One line response
    fancy = 2 # Fancy formatted response

class help_command_response():
    def __init__(self):
        super().__init__()
        self.command = None
        self.commandName = ""
        self.helpText = ""
        self.response = ""
        self.responseType = help_command_responseType.plain
        self.blockDecor = "\n================================================================\n"

    def setup(self, command, responseType):
        self.command = command
        self.commandName = command.command
        self.responseType = responseType

    def makeResponse(self):
        if self.responseType == help_command_responseType.plain:
            self.response_plain()
        elif self.responseType == help_command_responseType.fancy:
            self.response_fancy()

    def response_plain(self):
        tempHelpText = ""
        for line in self.command.help:
            tempHelpText = tempHelpText + line + " "
        self.response = "Command: " + self.commandName + " : " + self.helpText
        return self.response

    def response_fancy(self):
        tempHelpText = ""
        for line in self.command.help:
            tempHelpText = tempHelpText + line + "\n"
        self.response = self.blockDecor + "Command: " + self.commandName + self.blockDecor + tempHelpText + self.blockDecor
        return self.response



Help_Module_ = Help_Module()

if __name__ == "__main__":
    testModule = Help_Module()

    #credentials_manager = credentials.Credentials_Module()
    #credentials_manager.load_credentials()
    #testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
    testModule.main()