"""Entry-point shims: delegate to the brikc native binary."""
import os
import subprocess
import sys
from pathlib import Path


def _find_brikc() -> Path:
    """Locate the brikc binary bundled with this package or on PATH."""
    # 1. Bundled binary (set during install)
    pkg_dir = Path(__file__).parent
    for candidate in [pkg_dir / "bin" / "brikc_cli", pkg_dir / "bin" / "brikc"]:
        if candidate.is_file() and os.access(candidate, os.X_OK):
            return candidate
    # 2. PATH fallback
    import shutil
    found = shutil.which("brikc_cli") or shutil.which("brikc")
    if found:
        return Path(found)
    raise FileNotFoundError(
        "brikc binary not found. Re-install: pip install --force-reinstall brik64"
    )


def brikc() -> None:
    bin_path = _find_brikc()
    sys.exit(subprocess.call([str(bin_path)] + sys.argv[1:]))


def brikfmt() -> None:
    bin_path = _find_brikc()
    sys.exit(subprocess.call([str(bin_path), "fmt"] + sys.argv[1:]))


def brikcheck() -> None:
    bin_path = _find_brikc()
    sys.exit(subprocess.call([str(bin_path), "check"] + sys.argv[1:]))
