#!/bin/bash
# Test ntfy notification endpoints
# Tests both local and external ntfy servers

set -e

echo "🧪 ntfy Notification Test Script"
echo "================================"
echo

# Test local ntfy server (IP)
echo "📡 Testing Local ntfy Server (192.168.0.210:8081)..."
echo "------------------------------------------------------"
RESPONSE1=$(curl -s -d "🏠 Local ntfy test from $(hostname) at $(date)" http://192.168.0.210:8081/updates)
if echo "$RESPONSE1" | grep -q '"id"'; then
    echo "✅ Local ntfy server (IP) - SUCCESS"
    echo "   Response: $(echo "$RESPONSE1" | jq -r '.id')"
else
    echo "❌ Local ntfy server (IP) - FAILED"
    echo "   Response: $RESPONSE1"
fi
echo

# Test local ntfy server (localhost)
echo "📡 Testing Local ntfy Server (localhost:8081)..."
echo "-------------------------------------------------"
RESPONSE2=$(curl -s -d "🏠 Localhost ntfy test from $(hostname) at $(date)" http://localhost:8081/updates)
if echo "$RESPONSE2" | grep -q '"id"'; then
    echo "✅ Local ntfy server (localhost) - SUCCESS"
    echo "   Response: $(echo "$RESPONSE2" | jq -r '.id')"
else
    echo "❌ Local ntfy server (localhost) - FAILED"
    echo "   Response: $RESPONSE2"
fi
echo

# Test external ntfy server
echo "🌐 Testing External ntfy Server (ntfy.vish.gg)..."
echo "-------------------------------------------------"
RESPONSE3=$(curl -s -d "🌍 External ntfy test from $(hostname) at $(date)" https://ntfy.vish.gg/REDACTED_NTFY_TOPIC)
if echo "$RESPONSE3" | grep -q '"id"'; then
    echo "✅ External ntfy server - SUCCESS"
    echo "   Response: $(echo "$RESPONSE3" | jq -r '.id')"
else
    echo "❌ External ntfy server - FAILED"
    echo "   Response: $RESPONSE3"
fi
echo

echo "📋 Summary:"
echo "----------"
echo "Local ntfy (IP):        http://192.168.0.210:8081/updates"
echo "Local ntfy (localhost): http://localhost:8081/updates"
echo "External ntfy:          https://ntfy.vish.gg/REDACTED_NTFY_TOPIC"
echo

echo "🔧 Watchtower Configuration Options:"
echo "------------------------------------"
echo "Option 1 (Local IP):    WATCHTOWER_NOTIFICATION_URL=http://192.168.0.210:8081/updates"
echo "Option 2 (Localhost):   WATCHTOWER_NOTIFICATION_URL=http://localhost:8081/updates"
echo "Option 3 (External):    WATCHTOWER_NOTIFICATION_URL=https://ntfy.vish.gg/REDACTED_NTFY_TOPIC"
echo

echo "💡 Recommendation:"
echo "  - Use localhost for better reliability (no network dependency)"
echo "  - Use external for notifications REDACTED_APP_PASSWORD network"
echo "  - Consider using both (comma-separated) for redundancy"
echo

echo "✅ ntfy notification test complete!"
