#!/bin/bash

# Test curl komutları - POST response debug için
# API key: demo_key_12345 (config/security.yaml'dan)

BASE_URL="http://localhost:5000"
API_KEY="demo_key_12345"

echo "=========================================="
echo "1. Health Check (API key gerekmez)"
echo "=========================================="
curl -X GET "${BASE_URL}/health" -v

echo -e "\n\n=========================================="
echo "2. Info Endpoint (API key gerekir)"
echo "=========================================="
curl -X GET "${BASE_URL}/info" \
  -H "X-API-Key: ${API_KEY}" \
  -v

echo -e "\n\n=========================================="
echo "3. Channel ID ile Feed (Atom format)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_id=UC9h8BDcXwkhZtnqoQJ7PggA&format=Atom&max_items=5" \
  -H "X-API-Key: ${API_KEY}" \
  -v

echo -e "\n\n=========================================="
echo "4. Channel Handle ile Feed (@kurzgesagt)"
echo "   Not: İlk istekte 404 alınabilir (transcript henüz işlenmemiş)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel=@kurzgesagt&format=Atom&max_items=5" \
  -H "X-API-Key: ${API_KEY}" \
  -v

echo -e "\n\n=========================================="
echo "5. Channel URL ile Feed"
echo "   Not: İlk istekte 404 alınabilir (transcript henüz işlenmemiş)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_url=https://www.youtube.com/@kurzgesagt&format=Atom&max_items=5" \
  -H "X-API-Key: ${API_KEY}" \
  -v

echo -e "\n\n=========================================="
echo "6. RSS Format ile Feed"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_id=UC9h8BDcXwkhZtnqoQJ7PggA&format=Rss&max_items=5" \
  -H "X-API-Key: ${API_KEY}" \
  -v

echo -e "\n\n=========================================="
echo "7. API Key olmadan (401 hatası beklenir)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_id=UC9h8BDcXwkhZtnqoQJ7PggA&format=Atom" \
  -v

echo -e "\n\n=========================================="
echo "8. Geçersiz API Key ile (401 hatası beklenir)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_id=UC9h8BDcXwkhZtnqoQJ7PggA&format=Atom" \
  -H "X-API-Key: invalid_key" \
  -v

echo -e "\n\n=========================================="
echo "9. POST Response Debug Test (max_items=1, hızlı test)"
echo "   Not: İlk istekte 404 alınabilir (transcript henüz işlenmemiş)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_id=UCsXVk37bltHxD1rDPwtNM8Q&format=Atom&max_items=1" \
  -H "X-API-Key: ${API_KEY}" \
  -v \
  -o /tmp/test_feed.xml

echo -e "\n\n=========================================="
echo "10. Brotli Decode Test (yeni video ile)"
echo "    Not: İlk istekte 404 alınabilir (transcript henüz işlenmemiş)"
echo "=========================================="
curl -X GET "${BASE_URL}/?channel_id=UCsXVk37bltHxD1rDPwtNM8Q&format=Atom&max_items=1" \
  -H "X-API-Key: ${API_KEY}" \
  -v

echo -e "\n\n=========================================="
echo "Test tamamlandı!"
echo ""
echo "✅ Brotli desteği eklendi (requirements.txt)"
echo "   YouTube response'ları artık otomatik decode edilecek"
echo ""
echo "POST response debug dosyaları: output/flaresolverr_debug/"
echo "  - post_response_*.txt (her POST response)"
echo "  - post_response_error_*.txt (JSONDecodeError durumunda)"
echo ""
echo "⚠️  Docker container'ı yeniden build etmeniz gerekiyor:"
echo "   sudo docker compose down"
echo "   sudo docker compose build --no-cache"
echo "   sudo docker compose up -d"
echo "=========================================="

