#!/usr/bin/env bash
set -euo pipefail
echo "=== stop lab gameplay pilot on topbox250 ==="
pkill -f pog422_fixture_bridge 2>/dev/null || true
pkill -f pog422_uartd 2>/dev/null || true
sleep 2
pgrep -af 'pog422' || echo "no pog422 procs"
# Ensure synth stays off under prod
if [[ -f ~/EtherGold/fixture-bridge.env ]]; then
  sed -i 's/^LAB_GAMEPLAY_SYNTH=.*/LAB_GAMEPLAY_SYNTH=0/' ~/EtherGold/fixture-bridge.env 2>/dev/null || true
  if ! grep -q '^LAB_GAMEPLAY_SYNTH=' ~/EtherGold/fixture-bridge.env 2>/dev/null; then
    echo 'LAB_GAMEPLAY_SYNTH=0' >> ~/EtherGold/fixture-bridge.env
  fi
fi
sudo systemctl start fixture-prod
sleep 3
systemctl is-active fixture-prod
pgrep -af 'pog422_fixture_bridge' | head -2
# Confirm no lab gameplay flags on the running command line
if pgrep -af 'pog422_fixture_bridge' | grep -q lab-gameplay; then
  echo "WARN: lab-gameplay still on cmdline"
else
  echo "ok: no lab-gameplay on cmdline"
fi
echo "restored_prod"
