#!/bin/bash
# Auto-update game banners weekly
# Fetches latest banner data and updates JSON

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DATA_FILE="$SCRIPT_DIR/data.json"
API_KEY="${CHAT_SEARCH_API_KEY:-ocs_jjSV4579mEMNiXZx86awBDDuxOrbUDEmB9Ytbt5S2MEZvui5}"

echo "🎮 Auto-updating game banners..."
echo "Time: $(date)"
echo ""

# Fetch Genshin Impact data
echo "Fetching Genshin Impact banners..."
GENSHIN_RESPONSE=$(curl -s -X POST https://pwafbamvoajoiepdmzlz.supabase.co/functions/v1/chat-search \
  -H "Content-Type: application/json" \
  -H "x-api-key: $API_KEY" \
  -d '{
    "message": "What are the current Genshin Impact character and weapon banners? List all 5-star characters and weapons with their elements.",
    "sessionId": null,
    "createSessionIfMissing": true
  }')

# Fetch Wuthering Waves data
echo "Fetching Wuthering Waves banners..."
WW_RESPONSE=$(curl -s -X POST https://pwafbamvoajoiepdmzlz.supabase.co/functions/v1/chat-search \
  -H "Content-Type: application/json" \
  -H "x-api-key: $API_KEY" \
  -d '{
    "message": "What are the current and upcoming Wuthering Waves character banners? List all characters with their elements and weapons.",
    "sessionId": null,
    "createSessionIfMissing": true
  }')

echo ""
echo "✅ Data fetched successfully!"
echo ""
echo "Genshin Impact:"
echo "$GENSHIN_RESPONSE" | jq -r '.answer' | head -10
echo ""
echo "Wuthering Waves:"
echo "$WW_RESPONSE" | jq -r '.answer' | head -10
echo ""
echo "⚠️  Note: Review the data above and manually update $DATA_FILE if needed."
echo "    Images and exact dates should be verified from official sources."
