#!/bin/bash

# Sitemap Ping Script
# Notifies search engines of sitemap updates after deployment
# Usage: ./scripts/ping-sitemap.sh

set -e

SITE_URL="https://workroot.in"
SITEMAP_URL="${SITE_URL}/sitemap.xml"

echo "🔔 Pinging search engines about sitemap update..."
echo "Sitemap: $SITEMAP_URL"
echo ""

# Google
echo "📍 Pinging Google..."
GOOGLE_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "https://www.google.com/ping?sitemap=${SITEMAP_URL}")
if [ "$GOOGLE_RESPONSE" = "200" ]; then
  echo "✅ Google pinged successfully"
else
  echo "⚠️  Google ping returned HTTP $GOOGLE_RESPONSE"
fi

# Bing
echo "📍 Pinging Bing..."
BING_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "https://www.bing.com/ping?sitemap=${SITEMAP_URL}")
if [ "$BING_RESPONSE" = "200" ]; then
  echo "✅ Bing pinged successfully"
else
  echo "⚠️  Bing ping returned HTTP $BING_RESPONSE"
fi

echo ""
echo "✨ Sitemap ping complete!"
echo ""
echo "Next steps:"
echo "1. Check Google Search Console for indexing status"
echo "2. Check Bing Webmaster Tools for crawl stats"
echo "3. Monitor coverage reports in 24-48 hours"
