#!/usr/bin/env bash
set -euo pipefail

# PATH shim for python/python3 — intercepts bare invocations and
# suggests the uv equivalent.  Works for both names via $0.
cmd="$(basename "$0")"

case "${1:-}" in
  -V | --version)
    # Version checks are read-only diagnostics — pass through to the real
    # interpreter by skipping this shim's directory on PATH.
    shim_dir="$(cd "$(dirname "$0")" && pwd)"
    IFS=: read -ra path_entries <<<"${PATH:-}"
    for dir in "${path_entries[@]}"; do
      resolved="$(cd "$dir" 2>/dev/null && pwd)" || continue
      [[ "$resolved" == "$shim_dir" ]] && continue
      if [[ -x "$dir/$cmd" ]]; then
        exec "$dir/$cmd" "$1"
      fi
    done
    echo "ERROR: real $cmd binary not found on PATH" >&2
    exit 127
    ;;
  -m)
    case "${2:-}" in
      pip)
        echo "ERROR: \`$cmd -m pip\` is not supported. Use:" >&2
        echo "  uv add <package>       # add a dependency" >&2
        echo "  uv remove <package>    # remove a dependency" >&2
        ;;
      *)
        echo "ERROR: Use \`uv run $cmd -m ${2:-<module>}\` instead of \`$cmd -m ${2:-<module>}\`" >&2
        ;;
    esac
    ;;
  *)
    echo "ERROR: Use \`uv run $cmd ${*:-}\` instead of \`$cmd ${*:-}\`" >&2
    ;;
esac

exit 1
