#!/bin/bash
# Test Swagger UI Access

echo "🧪 Testing Swagger UI Access"
echo "============================"
echo ""

# Wait for app to start
echo "⏳ Waiting for app to start (30 seconds)..."
sleep 30

# Test Swagger UI
echo "Testing Swagger UI..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081/swagger-ui.html)

echo "HTTP Status Code: $HTTP_CODE"
echo ""

if [ "$HTTP_CODE" == "200" ]; then
    echo "✅ SUCCESS! Swagger UI is accessible"
    echo ""
    echo "🌐 Open in your browser:"
    echo "   http://localhost:8081/swagger-ui.html"
    echo ""
    echo "🔑 To test authenticated endpoints:"
    echo "   1. Get a token:"
    echo "      ./quick-test.sh"
    echo "   2. In Swagger UI, click 'Authorize'"
    echo "   3. Enter: Bearer YOUR_TOKEN"
    echo "   4. Click 'Authorize' and 'Close'"
    echo "   5. Now you can test any endpoint!"
elif [ "$HTTP_CODE" == "302" ]; then
    echo "✅ Swagger UI is accessible (redirecting)"
    echo "   Open: http://localhost:8081/swagger-ui.html"
elif [ "$HTTP_CODE" == "401" ]; then
    echo "❌ Still getting 401 - authentication required"
    echo "   The security config may not have updated yet"
    echo "   Try: docker-compose restart app"
else
    echo "⚠️  Got HTTP $HTTP_CODE"
    echo "   Check if app is running: docker-compose ps app"
fi
