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

DOMAINS=("realresultsready.com" "robblake.cloud")
GTM_ID="GTM-NKWJQWHF"
SAMPLE_PATHS=("/" "/about" "/tmp-demo-gannon/")
ALERT=0

for domain in "${DOMAINS[@]}"; do
  for path in "${SAMPLE_PATHS[@]}"; do
    url="https://${domain}${path}"
    status=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 "$url" || echo "000")

    if [ "$status" != "200" ]; then
      echo "DOWN: $url returned HTTP $status"
      ALERT=1
      continue
    fi

    body=$(curl -s --max-time 15 "$url" || true)
    if ! echo "$body" | grep -q "$GTM_ID"; then
      echo "GTM MISSING: $url does not contain $GTM_ID"
      ALERT=1
    fi
  done
done

exit $ALERT
