#!/usr/bin/env bash
# AI observability QA suite.
#
# Runs the static UI regression guard first, then production page smoke and
# rendered visual contract checks unless --skip-production is provided.

set -euo pipefail

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BASE_URL="https://mo.wooo.work"
SKIP_PRODUCTION=0

while [[ $# -gt 0 ]]; do
  case "$1" in
    --base-url)
      BASE_URL="${2:-}"
      if [[ -z "$BASE_URL" ]]; then
        echo "ERROR: --base-url requires a value" >&2
        exit 1
      fi
      shift 2
      ;;
    --skip-production)
      SKIP_PRODUCTION=1
      shift
      ;;
    -h|--help)
      cat <<'EOF'
Usage: scripts/check_observability_suite.sh [--base-url URL] [--skip-production]

Runs:
  1. python3 scripts/check_observability_ui.py
  2. python3 scripts/check_observability_deploy_gate.py --self-test
  3. python3 scripts/check_observability_pages.py --base-url URL
  4. scripts/check_observability_visual_contract.sh --base-url URL

Options:
  --base-url URL       Target site for the 10-page smoke check.
  --skip-production   Run only the static UI guard.
EOF
      exit 0
      ;;
    *)
      echo "ERROR: unknown option: $1" >&2
      exit 1
      ;;
  esac
done

cd "$PROJECT_ROOT"

echo "========================================"
echo "AI Observability QA Suite"
echo "========================================"
echo "1/4 Static UI guard"
python3 scripts/check_observability_ui.py
echo "2/4 Deploy gate self-test"
python3 scripts/check_observability_deploy_gate.py --self-test

if [[ "$SKIP_PRODUCTION" -eq 1 ]]; then
  echo "3/4 Production smoke skipped"
  echo "4/4 Rendered visual contract skipped"
  echo "AI Observability QA Suite: PASS"
  exit 0
fi

echo "3/4 Production 10-page smoke"
python3 scripts/check_observability_pages.py --base-url "$BASE_URL"
echo "4/4 Rendered visual contract"
bash scripts/check_observability_visual_contract.sh --base-url "$BASE_URL"

echo "AI Observability QA Suite: PASS"
