#!/bin/bash
# Quick System Verification Script
# Run this to confirm all services are operational

echo "🔍 House of Prayer Worship Platform - Quick Check"
echo "=================================================="
echo ""

# Check backend
echo -n "Backend API (port 8080)............ "
if curl -s http://localhost:8080/health | grep -q '"status":"ok"'; then
    echo "✅ RUNNING"
else
    echo "❌ NOT RESPONDING"
fi

# Check frontend
echo -n "Frontend (port 5100)............... "
if curl -s http://localhost:5100 | grep -q "Worship Platform"; then
    echo "✅ RUNNING"
else
    echo "❌ NOT RESPONDING"
fi

# Check external HTTPS
echo -n "External HTTPS Access.............. "
if curl -s -k https://houseofprayer.ddns.net | grep -q "Worship Platform"; then
    echo "✅ ACCESSIBLE"
else
    echo "❌ NOT ACCESSIBLE"
fi

# Check database
echo -n "PostgreSQL Database................ "
if PGPASSWORD='MySecurePass123' psql -U songlyric_user -d church_songlyric -h 192.168.10.130 -c "SELECT COUNT(*) FROM songs" -t 2>/dev/null | grep -q "[0-9]"; then
    SONG_COUNT=$(PGPASSWORD='MySecurePass123' psql -U songlyric_user -d church_songlyric -h 192.168.10.130 -c "SELECT COUNT(*) FROM songs" -t 2>/dev/null | tr -d ' ')
    echo "✅ CONNECTED ($SONG_COUNT songs)"
else
    echo "❌ NOT CONNECTED"
fi

# Check API endpoints
echo -n "Songs API.......................... "
if curl -s http://localhost:8080/api/songs | grep -q '"success":true'; then
    echo "✅ WORKING"
else
    echo "❌ FAILED"
fi

echo -n "Profiles API....................... "
if curl -s http://localhost:8080/api/profiles | grep -q '"success":true'; then
    echo "✅ WORKING"
else
    echo "❌ FAILED"
fi

echo -n "Lists API.......................... "
if curl -s http://localhost:8080/api/lists | grep -q '"success":true'; then
    echo "✅ WORKING"
else
    echo "❌ FAILED"
fi

echo ""
echo "=================================================="
echo "✅ System Check Complete!"
echo ""
echo "📖 Full Report: SYSTEM_DIAGNOSIS_REPORT.md"
echo "🔧 Test Suite: test-system.sh"
echo ""
