from ._HTMLTextFormatter import HTMLTextFormatter
from ._LineParser import (
    LineParser,
    JSON,
)


COMMANDS = {
    "{CMD_BREAK_LINE}": " ",
    "{CMD_SEPARATOR_EQUALS}": "=",
    "{CMD_SEPARATOR_DASH}": "-",
    "{CMD_NEW_PAGE}": "-",
}


class CommandLineParser(LineParser):

    def __init__(
        self,       # type: CommandLineParser
        columns,    # type: int
    ):
        # type: (...) -> None

        super(CommandLineParser, self).__init__(columns)

    def parse(
        self,    # type: CommandLineParser
        line,    # type: JSON
    ):

        parsed_command = self._parse_command(command=line.get("command"))
        html_text_formatter = HTMLTextFormatter(
            customization=line.get("customization"),
            columns=self.columns,
        )

        return [html_text_formatter.format(text=parsed_command)]

    def _parse_command(
        self,       # type: CommandLineParser
        command,    # type: str
    ):
        # type: (...) -> str

        parsed_command = COMMANDS.get(command, " ")
        return parsed_command * self.columns
