#!/usr/bin/env bash
# One-time setup check for LAV Pulse.
set -e
cd "$(dirname "$0")"

echo "── LAV Pulse setup ──────────────────────────────"

# 1. Node.js
if command -v node >/dev/null 2>&1; then
  echo "✓ Node.js $(node -v) found"
else
  echo "✗ Node.js not installed."
  echo "  → Install the LTS version from https://nodejs.org (or: brew install node), then re-run ./setup.sh"
  exit 1
fi

# 2. .env
if [ -f .env ]; then
  echo "✓ .env exists"
else
  cp .env.example .env
  echo "✓ Created .env (demo mode enabled)"
fi

# 3. Status of the two integrations
if grep -q '^DEMO_MODE=1' .env; then
  echo "• Running in DEMO mode. To connect real GA4: follow SETUP-GA4.md, then set DEMO_MODE=0 in .env"
fi
if grep -Eq '^OPENAI_API_KEY=sk-\.\.\.' .env || ! grep -Eq '^OPENAI_API_KEY=sk-' .env; then
  echo "• AI chat not configured yet. Add your key to .env:  OPENAI_API_KEY=sk-..."
else
  echo "✓ OpenAI key present — AI chat enabled"
fi
if [ -f ga4-service-account.json ]; then
  echo "✓ Google service-account key found"
else
  echo "• No ga4-service-account.json yet (needed only when you leave demo mode — see SETUP-GA4.md)"
fi

chmod +x run.sh 2>/dev/null || true
echo "─────────────────────────────────────────────────"
echo "Done. Start the dashboard with:  ./run.sh    (default port 5001; override with PORT=xxxx ./run.sh)"
