#!/bin/bash

# Quick script to start queue worker with helpful output

echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║           📧 STARTING EMAIL QUEUE WORKER                      ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo ""

# Check pending jobs
PENDING=$(php artisan tinker --execute="echo DB::table('jobs')->count();" 2>/dev/null | tail -1)
FAILED=$(php artisan tinker --execute="echo DB::table('failed_jobs')->count();" 2>/dev/null | tail -1)

echo "📊 Current Queue Status:"
echo "   Pending emails: $PENDING"
echo "   Failed emails:  $FAILED"
echo ""

if [ "$PENDING" -gt 0 ]; then
    echo "✅ Found $PENDING emails to process!"
    echo ""
else
    echo "ℹ️  No emails in queue (queue is empty)"
    echo ""
fi

echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Starting queue worker..."
echo "Press Ctrl+C to stop"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Start queue worker with verbose output
php artisan queue:work --verbose --tries=3 --timeout=60
