from .code_tables import COMP_TABLE, DEST_TABLE, JUMP_TABLE


class Code:
    """Translates Hack assembly mnemonics into binary codes."""

    @staticmethod
    def dest(mnemonic: str) -> str:
        """
        Returns the 3-bit binary code for the dest mnemonic.

        Args:
            mnemonic: Destination mnemonic (e.g., "M", "D", "MD", "AMD")

        Returns:
            3-bit binary string (e.g., "010", "111")

        Raises:
            KeyError: If mnemonic is invalid
        """
        # Use dictionary lookup table
        return DEST_TABLE[mnemonic]

    @staticmethod
    def comp(mnemonic: str) -> str:
        """
        Returns the 7-bit binary code for the comp mnemonic.

        Args:
            mnemonic: Computation mnemonic (e.g., "D+1", "M-1", "D&A")

        Returns:
            7-bit binary string (e.g., "0001111", "1110000")

        Raises:
            KeyError: If mnemonic is invalid
        """
        # Use dictionary lookup table
        return COMP_TABLE[mnemonic]

    @staticmethod
    def jump(mnemonic: str) -> str:
        """
        Returns the 3-bit binary code for the jump mnemonic.

        Args:
            mnemonic: Jump mnemonic (e.g., "JGT", "JEQ", "JMP", or "" for no jump)

        Returns:
            3-bit binary string (e.g., "001", "111")

        Raises:
            KeyError: If mnemonic is invalid
        """
        # Use dictionary lookup table
        return JUMP_TABLE[mnemonic]
