#!/usr/bin/env bash
# iyzico panel yeniden başvurusu öncesi vitrin yüzey kontrolü (HTTP durum + taslak ifade taraması).
# Kullanım: FAUNAMIX_SITE_URL=https://www.faunamix.com ./scripts/verify-iyzico-site-checklist.sh
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
SITE="${FAUNAMIX_SITE_URL:-https://www.faunamix.com}"
SITE="${SITE%/}"

PATHS=(
  "/gizlilik"
  "/mesafeli-satis"
  "/iade-kosullari"
  "/hakkimizda"
  "/iletisim"
  "/arama-sonuclari"
  "/sepet"
)

DRAFT_MARKERS=("yayın öncesi" "güncellenecektir" "taslak metin" "test tr" "Veysel Test" "lorem ipsum")
EXIT=0

echo "iyzico site checklist: $SITE"
echo ""

for p in "${PATHS[@]}"; do
  url="$SITE$p"
  code="$(curl -sS -o /tmp/faunamix-check-body.html -w '%{http_code}' -L --max-time 25 "$url" || echo "000")"
  if [[ "$code" != "200" ]]; then
    echo "[BLOCKER] $p HTTP $code"
    EXIT=1
    continue
  fi
  body="$(cat /tmp/faunamix-check-body.html)"
  draft_hit=""
  for m in "${DRAFT_MARKERS[@]}"; do
    if [[ "$body" == *"$m"* ]]; then
      draft_hit="$m"
      break
    fi
  done
  if [[ -n "$draft_hit" ]]; then
    echo "[BLOCKER] $p taslak ifade: $draft_hit"
    EXIT=1
  else
    echo "[OK] $p"
  fi
done

rm -f /tmp/faunamix-check-body.html

if [[ "$EXIT" -eq 0 ]]; then
  echo ""
  echo "Yüzey kontrolü geçti. Ardından: php scripts/verify-legal-readiness.php"
else
  echo ""
  echo "Eksikler giderildikten sonra iyzico başvurusunu yenileyin."
fi

exit "$EXIT"
