package seedu.ezdo.logic;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;

import seedu.ezdo.commons.exceptions.AliasAlreadyInUseException;
import seedu.ezdo.commons.exceptions.CommandDoesNotExistException;
import seedu.ezdo.logic.commands.AddCommand;
import seedu.ezdo.logic.commands.AliasCommand;
import seedu.ezdo.logic.commands.ClearCommand;
import seedu.ezdo.logic.commands.DoneCommand;
import seedu.ezdo.logic.commands.EditCommand;
import seedu.ezdo.logic.commands.FindCommand;
import seedu.ezdo.logic.commands.HelpCommand;
import seedu.ezdo.logic.commands.KillCommand;
import seedu.ezdo.logic.commands.ListCommand;
import seedu.ezdo.logic.commands.QuitCommand;
import seedu.ezdo.logic.commands.RedoCommand;
import seedu.ezdo.logic.commands.SaveCommand;
import seedu.ezdo.logic.commands.SelectCommand;
import seedu.ezdo.logic.commands.SortCommand;
import seedu.ezdo.logic.commands.UndoCommand;

/**
 * Keeps track of the command aliases specified by user.
 */
public class CommandAliases implements Serializable {

    private static final String[] EXISTING_COMMAND_WORDS = {AddCommand.COMMAND_WORD,
                                                            AddCommand.SHORT_COMMAND_WORD,
                                                            AliasCommand.COMMAND_WORD,
                                                            EditCommand.COMMAND_WORD,
                                                            EditCommand.SHORT_COMMAND_WORD,
                                                            SelectCommand.COMMAND_WORD,
                                                            KillCommand.COMMAND_WORD,
                                                            KillCommand.SHORT_COMMAND_WORD,
                                                            ClearCommand.COMMAND_WORD,
                                                            ClearCommand.SHORT_COMMAND_WORD,
                                                            FindCommand.COMMAND_WORD,
                                                            FindCommand.SHORT_COMMAND_WORD,
                                                            ListCommand.COMMAND_WORD,
                                                            ListCommand.SHORT_COMMAND_WORD,
                                                            QuitCommand.COMMAND_WORD,
                                                            QuitCommand.SHORT_COMMAND_WORD,
                                                            DoneCommand.COMMAND_WORD,
                                                            DoneCommand.SHORT_COMMAND_WORD,
                                                            HelpCommand.COMMAND_WORD,
                                                            HelpCommand.SHORT_COMMAND_WORD,
                                                            SortCommand.COMMAND_WORD,
                                                            SortCommand.SHORT_COMMAND_WORD,
                                                            SaveCommand.COMMAND_WORD,
                                                            UndoCommand.COMMAND_WORD,
                                                            UndoCommand.SHORT_COMMAND_WORD,
                                                            RedoCommand.COMMAND_WORD,
                                                            RedoCommand.SHORT_COMMAND_WORD};

    private HashMap<String, String> commandAliasesMap;

    public CommandAliases() {
        this.commandAliasesMap = new HashMap<>();
    }

    public void addAlias(String command, String alias) throws AliasAlreadyInUseException, CommandDoesNotExistException {
        if (Arrays.asList(EXISTING_COMMAND_WORDS).contains(alias)) {
            throw new AliasAlreadyInUseException();
        }
        if (!Arrays.asList(EXISTING_COMMAND_WORDS).contains(command)) {
            throw new CommandDoesNotExistException();
        }
        commandAliasesMap.put(alias, command);
    }

    public boolean isAlias(String alias) {
        return commandAliasesMap.get(alias) != null;
    }

    public String getCommandFromAlias(String alias) {
        return commandAliasesMap.get(alias);
    }

}

@@ -1135,68 +1135,8 @@
 ORD,
-%0A                                                           
  Add
@@ -1223,21 +1223,21 @@
         
-Alias
+Clear
 Command.
@@ -1253,81 +1253,22 @@
 ORD,
-%0A                                                            Edit
+ Clear
 Command.
 COMM
@@ -1255,32 +1255,38 @@
 D, ClearCommand.
+SHORT_
 COMMAND_WORD,%0A  
@@ -1347,20 +1347,20 @@
     
-Edit
+Done
 Command.
 SHOR
@@ -1347,38 +1347,32 @@
     DoneCommand.
-SHORT_
 COMMAND_WORD,%0A  
@@ -1372,83 +1372,21 @@
 ORD,
-%0A                                                            Select
+ Done
 Command.
 COMM
@@ -1373,32 +1373,38 @@
 RD, DoneCommand.
+SHORT_
 COMMAND_WORD,%0A  
@@ -1453,36 +1453,36 @@
                 
-Kill
+Edit
 Command.COMMAND_
@@ -1490,73 +1490,13 @@
 ORD,
-%0A                                                            Kill
+ Edit
 Comm
@@ -1571,37 +1571,36 @@
                 
-Clear
+Find
 Command.COMMAND_
@@ -1608,74 +1608,13 @@
 ORD,
-%0A                                                            Clear
+ Find
 Comm
@@ -1689,36 +1689,36 @@
                 
-Find
+Help
 Command.COMMAND_
@@ -1726,73 +1726,13 @@
 ORD,
-%0A                                                            Find
+ Help
 Comm
@@ -1807,36 +1807,36 @@
                 
-List
+Kill
 Command.COMMAND_
@@ -1844,73 +1844,13 @@
 ORD,
-%0A                                                            List
+ Kill
 Comm
@@ -1925,35 +1925,35 @@
                 
-Qui
+Lis
 tCommand.COMMAND
@@ -1962,72 +1962,12 @@
 ORD,
-%0A                                                            Qui
+ Lis
 tCom
@@ -2043,36 +2043,36 @@
                 
-Done
+Quit
 Command.COMMAND_
@@ -2080,73 +2080,13 @@
 ORD,
-%0A                                                            Done
+ Quit
 Comm
@@ -2161,36 +2161,36 @@
                 
-Help
+Redo
 Command.COMMAND_
@@ -2198,73 +2198,13 @@
 ORD,
-%0A                                                            Help
+ Redo
 Comm
@@ -2316,68 +2316,8 @@
 ORD,
-%0A                                                           
  Sor
@@ -2405,20 +2405,20 @@
         
-Save
+Undo
 Command.
@@ -2434,68 +2434,8 @@
 ORD,
-%0A                                                           
  Und
@@ -2435,32 +2435,38 @@
 RD, UndoCommand.
+SHORT_
 COMMAND_WORD,%0A  
@@ -2523,28 +2523,29 @@
         
-Undo
+Alias
 Command.
 SHORT_CO
@@ -2528,38 +2528,32 @@
    AliasCommand.
-SHORT_
 COMMAND_WORD,%0A  
@@ -2602,36 +2602,36 @@
                 
-Redo
+Save
 Command.COMMAND_
@@ -2696,28 +2696,30 @@
         
-Redo
+Select
 Command.
 SHORT_CO
@@ -2702,38 +2702,32 @@
   SelectCommand.
-SHORT_
 COMMAND_WORD%7D;%0A%0A

Reformat EXISTING_COMMAND_WORDS declaration