package seedu.task.logic.commandlibrary;

import static seedu.task.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;

import java.util.HashMap;

import seedu.task.logic.commands.AddCommand;
import seedu.task.logic.commands.ClearCommand;
import seedu.task.logic.commands.Command;
import seedu.task.logic.commands.DeleteCommand;
import seedu.task.logic.commands.DoneCommand;
import seedu.task.logic.commands.EditCommand;
import seedu.task.logic.commands.ExitCommand;
import seedu.task.logic.commands.FindCommand;
import seedu.task.logic.commands.FindExactCommand;
import seedu.task.logic.commands.HelpCommand;
import seedu.task.logic.commands.HelpFormatCommand;
import seedu.task.logic.commands.IncorrectCommand;
import seedu.task.logic.commands.ListByDoneCommand;
import seedu.task.logic.commands.ListByNotDoneCommand;
import seedu.task.logic.commands.ListByTagCommand;
import seedu.task.logic.commands.ListCommand;
import seedu.task.logic.commands.LoadCommand;
import seedu.task.logic.commands.SaveCommand;
import seedu.task.logic.commands.UnDoneCommand;
import seedu.task.logic.commands.UndoCommand;
import seedu.task.logic.parser.AddCommandParser;
import seedu.task.logic.parser.ClearCommandParser;
import seedu.task.logic.parser.CommandParser;
import seedu.task.logic.parser.DeleteCommandParser;
import seedu.task.logic.parser.EditCommandParser;
import seedu.task.logic.parser.EditIsDoneCommandParser;
import seedu.task.logic.parser.EditUnDoneCommandParser;
import seedu.task.logic.parser.ExitCommandParser;
import seedu.task.logic.parser.FindCommandParser;
import seedu.task.logic.parser.FindExactCommandParser;
import seedu.task.logic.parser.HelpCommandParser;
import seedu.task.logic.parser.HelpFormatCommandParser;
import seedu.task.logic.parser.ListByDoneCommandParser;
import seedu.task.logic.parser.ListByNotDoneCommandParser;
import seedu.task.logic.parser.ListByTagCommandParser;
import seedu.task.logic.parser.ListCommandParser;
import seedu.task.logic.parser.LoadCommandParser;
import seedu.task.logic.parser.SaveCommandParser;
import seedu.task.logic.parser.UndoCommandParser;

public class CommandLibrary {

    private static CommandLibrary instance = null;
    private static HashMap<String, CommandParser> commandParserTable;
//    private static commandKeyParserPair[] commandKeyParserPairs;

    protected CommandLibrary() {
        init();
    }

    public static CommandLibrary getInstance() {
        if (instance == null) {
            instance = new CommandLibrary();
        }
        return instance;
    }

    /**
     * To initialize the hashmap and necessary variables
     */
    private static void init() {
        commandParserTable =  new HashMap<>();
        // TODO Auto-generated method stub
        commandParserTable.put(AddCommand.COMMAND_WORD_1, new AddCommandParser());

        commandParserTable.put(ClearCommand.COMMAND_WORD_1, new ClearCommandParser());

        commandParserTable.put(DeleteCommand.COMMAND_WORD_1, new DeleteCommandParser());

        commandParserTable.put(DoneCommand.COMMAND_WORD_1, new EditIsDoneCommandParser());
        commandParserTable.put(DoneCommand.COMMAND_WORD_2, new EditIsDoneCommandParser());

        commandParserTable.put(EditCommand.COMMAND_WORD_1, new EditCommandParser());

        commandParserTable.put(ExitCommand.COMMAND_WORD_1, new ExitCommandParser());

        commandParserTable.put(FindCommand.COMMAND_WORD_1, new FindCommandParser());
        commandParserTable.put(FindCommand.COMMAND_WORD_2, new FindCommandParser());

        commandParserTable.put(FindExactCommand.COMMAND_WORD_1, new FindExactCommandParser());
        commandParserTable.put(FindExactCommand.COMMAND_WORD_2, new FindExactCommandParser());
        commandParserTable.put(FindExactCommand.COMMAND_WORD_3, new FindExactCommandParser());
        commandParserTable.put(FindExactCommand.COMMAND_WORD_4, new FindExactCommandParser());

        commandParserTable.put(HelpCommand.COMMAND_WORD_1, new HelpCommandParser());
        commandParserTable.put(HelpCommand.COMMAND_WORD_2, new HelpCommandParser());

        commandParserTable.put(HelpFormatCommand.COMMAND_WORD_1, new HelpFormatCommandParser());
        commandParserTable.put(HelpFormatCommand.COMMAND_WORD_2, new HelpFormatCommandParser());
        commandParserTable.put(HelpFormatCommand.COMMAND_WORD_3, new HelpFormatCommandParser());
        commandParserTable.put(HelpFormatCommand.COMMAND_WORD_4, new HelpFormatCommandParser());
        commandParserTable.put(HelpFormatCommand.COMMAND_WORD_5, new HelpFormatCommandParser());
        commandParserTable.put(HelpFormatCommand.COMMAND_WORD_6, new HelpFormatCommandParser());

        commandParserTable.put(ListByDoneCommand.COMMAND_WORD_1, new ListByDoneCommandParser());
        commandParserTable.put(ListByDoneCommand.COMMAND_WORD_2, new ListByDoneCommandParser());

        commandParserTable.put(ListByNotDoneCommand.COMMAND_WORD_1, new ListByNotDoneCommandParser());
        commandParserTable.put(ListByNotDoneCommand.COMMAND_WORD_2, new ListByNotDoneCommandParser());
        commandParserTable.put(ListByNotDoneCommand.COMMAND_WORD_3, new ListByNotDoneCommandParser());

        commandParserTable.put(ListByTagCommand.COMMAND_WORD_1, new ListByTagCommandParser());
        commandParserTable.put(ListByTagCommand.COMMAND_WORD_2, new ListByTagCommandParser());
        commandParserTable.put(ListByTagCommand.COMMAND_WORD_3, new ListByTagCommandParser());
        commandParserTable.put(ListByTagCommand.COMMAND_WORD_4, new ListByTagCommandParser());

        commandParserTable.put(ListCommand.COMMAND_WORD_1, new ListCommandParser());
        commandParserTable.put(ListCommand.COMMAND_WORD_2, new ListCommandParser());
        commandParserTable.put(ListCommand.COMMAND_WORD_3, new ListCommandParser());

        commandParserTable.put(LoadCommand.COMMAND_WORD_1, new LoadCommandParser());

        commandParserTable.put(SaveCommand.COMMAND_WORD_1, new SaveCommandParser());

        commandParserTable.put(UndoCommand.COMMAND_WORD_1, new UndoCommandParser());
        commandParserTable.put(UndoCommand.COMMAND_WORD_2, new UndoCommandParser());

        commandParserTable.put(UnDoneCommand.COMMAND_WORD_1, new EditUnDoneCommandParser());
        commandParserTable.put(UnDoneCommand.COMMAND_WORD_2, new EditUnDoneCommandParser());

//        for(commandKeyParserPair pair: commandKeyParserPairs){
//            commandParserTable.put(pair.getKey(), pair.getParser());
//        }
    }
    /**
     *
     * @param commandWord
     * @param arguments
     * @return Returns the correct command with the correct arguments
     */
    public Command getCorrectCommand(String commandWord, String arguments){
        if(!commandParserTable.containsKey(commandWord))  {return new IncorrectCommand(MESSAGE_UNKNOWN_COMMAND);}
        return  commandParserTable.get(commandWord).parse(arguments);
    }
//    protected class commandKeyParserPair{
//        private String commandKey;
//        private CommandParser commandParser;
//
//        protected commandKeyParserPair(String commandKey, CommandParser commandParser){
//            this.commandKey = commandKey;
//            this.commandParser =(CommandParser) commandParser;
//        }
//
//        public String getKey(){
//            return this.commandKey;
//        }
//        public CommandParser getParser(){
//            return this.commandParser;
//        }
//    }
}

@@ -6689,16 +6689,17 @@
 guments)
+ 
 %7B%0A      
@@ -6702,16 +6702,17 @@
       if
+ 
 (!comman
@@ -6750,18 +6750,30 @@
 dWord)) 
- 
 %7B
+%0A            
 return n
@@ -6817,16 +6817,25 @@
 OMMAND);
+%0A        
 %7D%0A      

fix checkstyle