"""Which fine-tuning backend (if any) this machine can actually run. Deliberately
avoids importing torch/mlx to check — those are the whole hardware-specific
dependencies this module exists to gate, so detection has to be cheap and dependency
-free (platform introspection + checking for the `nvidia-smi` CLI, not a Python import
that might not even be installed)."""

import platform
import shutil
from typing import Literal

Backend = Literal["mlx", "cuda", "unavailable"]


def detect_backend() -> Backend:
    if platform.system() == "Darwin" and platform.machine() == "arm64":
        return "mlx"
    if shutil.which("nvidia-smi") is not None:
        return "cuda"
    return "unavailable"
