#!/bin/bash

echo "========================================="
echo "Checking SkyArtShop Backend Status"
echo "========================================="
echo ""

# Check if database tables exist
echo "1. Checking database tables..."
PGPASSWORD=SkyArt2025Pass! psql -U skyartapp -d skyartshop -c "\dt" 2>&1 | grep -E "adminusers|appusers|session|No relations"

echo ""
echo "2. Checking if adminusers table exists and count..."
PGPASSWORD=SkyArt2025Pass! psql -U skyartapp -d skyartshop -c "SELECT COUNT(*) FROM adminusers;" 2>&1

echo ""
echo "3. Listing all admin users..."
PGPASSWORD=SkyArt2025Pass! psql -U skyartapp -d skyartshop -c "SELECT id, email, name, role, createdat FROM adminusers;" 2>&1

echo ""
echo "4. Checking if Node.js backend is running..."
ps aux | grep "node.*server.js" | grep -v grep

echo ""
echo "5. Checking if port 3001 is in use..."
netstat -tlnp 2>/dev/null | grep :3001 || ss -tlnp 2>/dev/null | grep :3001 || echo "Port 3001 not in use"

echo ""
echo "========================================="
