package terminal;

import static terminal.SelectGraphicRendition.SGR_COMMAND;

import java.util.HashMap;
import java.util.Map;

import terminal.ControlSequence.NullControlSequence;

public class ControlSequenceLookup {

    private Map<Character, Map<String, ControlSequence>> commands;

    public ControlSequenceLookup() {
        this.commands = new HashMap<>();

        initializeCommands();
    }

    private void initializeCommands() {
        Map<String, ControlSequence> sgrCodes = new HashMap<>();

        for (SelectGraphicRendition sgr : SelectGraphicRendition.values())
            sgrCodes.put(sgr.getCode(), sgr);

        commands.put(SGR_COMMAND, sgrCodes);
    }

    public ControlSequence get(char command, String code) {
        Map<String, ControlSequence> codes = commands.getOrDefault(command, new HashMap<>());

        return codes.getOrDefault(code, new NullControlSequence());
    }

}