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

tool_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if ! command -v python3 >/dev/null 2>&1; then
    echo "Python 3 is required. Use a native Python 3 build appropriate for this Mac, then rerun this script." >&2
    exit 1
fi

python3 - <<'PY'
import sys
if sys.version_info < (3, 8):
    raise SystemExit("Python 3.8 or newer is required")
PY

python3 -m venv "$tool_dir/.venv"
"$tool_dir/.venv/bin/python" -m pip install --upgrade pip
"$tool_dir/.venv/bin/python" -m pip install -r "$tool_dir/requirements.txt"

echo "Mac flash tools installed in $tool_dir/.venv"
echo "Connect the ESP32-S3 with a data-capable USB cable, then run:"
echo "  ./tools/mac/device.sh backup m5stack-stopwatch"

