<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('events', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->foreignId('association_id')->constrained('associations')->cascadeOnDelete();
            
            // Basic Info
            $table->string('title');
            $table->text('description')->nullable();
            $table->enum('event_type', ['meeting', 'conference', 'social', 'fundraiser', 'workshop', 'other'])->default('meeting');
            $table->string('category')->nullable();
            
            // Dates & Time
            $table->timestamp('starts_at');
            $table->timestamp('ends_at');
            $table->string('timezone')->default('Africa/Lagos');
            
            // Location
            $table->enum('location_type', ['physical', 'virtual', 'hybrid'])->default('physical');
            $table->string('venue_name')->nullable();
            $table->text('venue_address')->nullable();
            $table->string('city')->nullable();
            $table->string('state')->nullable();
            $table->string('virtual_link')->nullable();
            
            // Registration
            $table->boolean('requires_registration')->default(true);
            $table->integer('max_attendees')->nullable();
            $table->integer('current_attendees')->default(0);
            $table->timestamp('registration_deadline')->nullable();
            
            // Fees
            $table->boolean('is_paid')->default(false);
            $table->decimal('ticket_price', 12, 2)->nullable();
            $table->decimal('early_bird_price', 12, 2)->nullable();
            $table->timestamp('early_bird_deadline')->nullable();
            
            // Approval Workflow
            $table->foreignId('created_by')->constrained('users');
            $table->foreignId('approved_by')->nullable()->constrained('users');
            $table->enum('approval_status', ['draft', 'pending', 'approved', 'rejected'])->default('draft');
            $table->timestamp('approved_at')->nullable();
            $table->text('rejection_reason')->nullable();
            
            // Status
            $table->enum('status', ['upcoming', 'ongoing', 'completed', 'cancelled'])->default('upcoming');
            
            $table->timestamps();
            $table->softDeletes();
            
            $table->index(['association_id', 'status', 'starts_at']);
            $table->index('approval_status');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('events');
    }
};
