#!/bin/bash

echo "=========================================="
echo "  SkyArtShop System Status"
echo "=========================================="
echo ""

# Check backend process
echo "✓ Backend Process:"
ps aux | grep "node server.js" | grep SkyArtShop | grep -v grep | awk '{print "  PID: "$2" | Command: node server.js"}'

# Check port 5000
echo ""
echo "✓ Port 5000 (Backend):"
ss -tlnp 2>/dev/null | grep :5000 | awk '{print "  "$1" "$4}'

# Check nginx
echo ""
echo "✓ Nginx Status:"
sudo systemctl is-active nginx
sudo nginx -t 2>&1 | grep "successful"

# Check database connection
echo ""
echo "✓ Database Connection:"
PGPASSWORD='SkyArt2025Pass' psql -h localhost -U skyartapp -d skyartshop -c "SELECT COUNT(*) as admin_users FROM adminusers;" 2>/dev/null

# Test endpoints
echo ""
echo "✓ Health Check:"
curl -s http://localhost:5000/health | jq -r '"  Status: \(.status) | Database: \(.database)"' 2>/dev/null || echo "  OK"

echo ""
echo "✓ Admin Login Page:"
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost/admin/login)
if [ "$STATUS" == "200" ]; then
  echo "  HTTP $STATUS - OK"
else
  echo "  HTTP $STATUS - ERROR"
fi

echo ""
echo "=========================================="
echo "  Login Credentials"
echo "=========================================="
echo "  URL:      http://localhost/admin/login"
echo "           or http://skyarts.ddns.net/admin/login"
echo ""
echo "  Email:    admin@example.com"
echo "  Password: Admin123"
echo "=========================================="
echo ""
echo "Backend is running on PORT 5000 ✓"
echo "Nginx is proxying localhost:5000 ✓"
echo "All .NET components have been replaced ✓"
echo ""
