#!/bin/bash
# Verify Capacity Stats Fix is Working
# Run this after restarting backend server

echo "==================================="
echo "Capacity Stats Fix Verification"
echo "==================================="
echo ""

echo "1. Checking all events with seats:"
php artisan tinker --execute="
\$events = DB::table('events')
    ->join('seats', 'events.id', '=', 'seats.event_id')
    ->select('events.id', 'events.name', DB::raw('COUNT(*) as total_records'))
    ->groupBy('events.id', 'events.name')
    ->get();

foreach (\$events as \$event) {
    \$bookable = DB::table('seats')
        ->where('event_id', \$event->id)
        ->whereIn('seat_type', ['individual', 'table_child'])
        ->count();

    \$parents = \$event->total_records - \$bookable;

    echo \"Event {\$event->id}: {\$event->name}\\n\";
    echo \"  Total records: {\$event->total_records}\\n\";
    echo \"  Bookable seats: {\$bookable}\\n\";
    echo \"  Parent tables: {\$parents}\\n\";
    echo \"\\n\";
}
"

echo ""
echo "2. Test API endpoint (requires auth token):"
echo "   Visit http://localhost:3001/events"
echo "   Check capacity shows: X/Y where Y = bookable seats only"
echo ""
echo "3. Expected behavior:"
echo "   - Capacity should NOT include parent table records"
echo "   - Only individual + table_child seats counted"
echo ""
echo "==================================="
