#!/bin/bash

# Seed Mohamed Abdo New Years Event to Production
# Usage: ./scripts/seed-mohamed-abdo-event.sh

set -e

echo "🌱 Seeding Mohamed Abdo New Years 2025 Event..."
echo ""

# Detect PHP binary
if [ -f "/opt/cpanel/ea-php82/root/usr/bin/php" ]; then
    PHP="/opt/cpanel/ea-php82/root/usr/bin/php"
else
    PHP="php"
fi

# Run tinker command to seed event
$PHP artisan tinker --execute="
use App\Model\Event;
use Illuminate\Support\Facades\DB;

DB::beginTransaction();

try {
    // Check if event already exists
    \$existing = Event::where('slug', 'mohamed-abdo-new-years-celebration-2025')->first();

    if (\$existing) {
        echo '⚠️  Event already exists: ID ' . \$existing->id . '\n';
        echo '   To recreate, delete first: Event::find(' . \$existing->id . ')->delete();\n';
        DB::rollBack();
        exit(1);
    }

    // Create the event
    \$event = Event::create([
        'name' => 'Mohamed Abdo New Years Celebration 2025',
        'event_type' => 'concert',
        'event_image_url' => 'https://dev.globalgalashow.com/storage/cms/general/1761937103_IjQNHBoeBH1Ozb0b.jpeg',
        'organizer_name' => 'Global Gala Ltd',
        'organizer_email' => 'contact@globalgala.com',
        'organizer_phone' => '000',
        'start_date' => '2025-12-30',
        'start_time' => '22:00:00',
        'doors_open_time' => '04:00:00',
        'timezone' => 'Europe/London',
        'description' => 'Celebrating the new year 2026 with Mohamed Abdo and special guests!',
        'slug' => 'mohamed-abdo-new-years-celebration-2025',
        'address' => 'The Great Room, Grosvenor House, Park Ln, London W1K 7TN',
        'status' => 1,
        'is_featured' => true,
        'is_published' => true,
        'publish_website' => true,
    ]);

    echo '✅ Event created successfully!\n';
    echo '   ID: ' . \$event->id . '\n';
    echo '   Name: ' . \$event->name . '\n';
    echo '   Slug: ' . \$event->slug . '\n';
    echo '   Published: ' . (\$event->is_published ? 'YES' : 'NO') . '\n';
    echo '   Featured: ' . (\$event->is_featured ? 'YES' : 'NO') . '\n';

    DB::commit();

} catch (Exception \$e) {
    DB::rollBack();
    echo '❌ Error: ' . \$e->getMessage() . '\n';
    exit(1);
}
"

echo ""
echo "✅ Seeding complete!"
echo ""
echo "📋 Next steps:"
echo "   1. Verify: curl https://api.globalgala.com/api/events"
echo "   2. View frontend: https://globalgala.com"
echo "   3. Copy venue from old event (if needed)"
echo ""
