import logging
from thefuzz import process
KNOWN_COMMANDS = [
    # Git commands
    'git status',
    'git commit',
    'git push',
    'git pull',
    'git add',
    'git clone',
    'git checkout',
    'git branch',
    'git merge',
    'git log',
    'git diff',
    'git reset',
    'git rm',
    'git mv',
    'git fetch',
    'git rebase',
    'git stash',
    'git tag',
    'git show',
    'git remote',
    'git init',
    'git config',
    'git clean',
    'git describe',
    'git blame',
    'git cherry-pick',
    'git archive',
    'git submodule',
    # Linux commands
    'ls',
    'cd',
    'pwd',
    'cp',
    'mv',
    'rm',
    'mkdir',
    'rmdir',
    'touch',
    'cat',
    'echo',
    'head',
    'tail',
    'less',
    'more',
    'find',
    'grep',
    'chmod',
    'chown',
    'man',
    'which',
    'whereis',
    'locate',
    'df',
    'du',
    'top',
    'ps',
    'kill',
    'ping',
    'wget',
    'curl',
    'tar',
    'zip',
    'unzip',
    'ssh',
    'scp',
    'sudo',
    'apt-get',
    'apt',
    'yum',
    'service',
    'systemctl',
    'journalctl',
    'history',
    'alias',
    'env',
    'export',
    'uname',
    'date',
    'cal',
    'whoami',
    'hostname',
    'ifconfig',
    'ip',
    'netstat',
    'mount',
    'umount',
    'free',
    'uptime',
    'dmesg',
    'lsblk',
    'lsusb',
    'lspci',
    'groups',
    'passwd',
    'useradd',
    'usermod',
    'userdel',
    'groupadd',
    'groupdel',
    'crontab',
    'at',
    'bg',
    'fg',
    'jobs',
    'nohup',
    'xargs',
    'sort',
    'uniq',
    'diff',
    'comm',
    'tee',
    'awk',
    'sed',
    'cut',
    'tr',
    'paste',
    'column',
    'printf',
    'bc',
    'expr',
    'yes',
    'sleep',
    'time',
    'watch',
    'clear',
    'exit',
]


def get_best_match(cmd: str) -> str:
    """
    Returns the best matching command from the known command list using fuzzy matching.
    Args:
        cmd (str): The mistyped command string.
    Returns:
        str: The best matched command if confidence is high, otherwise '<no suggestion>'.
    """
    match, score = process.extractOne(cmd, KNOWN_COMMANDS)
    logging.info(f"Best match for '{cmd}' is '{match}' with score {score}")
    # Lower threshold to 70 for better matching
    if match and score >= 70:
        return match
    return '<no suggestion>'
