<?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::table('meetup_booths', function (Blueprint $table) {
            $table->boolean('voting_enabled')->default(false)->after('status');
        });

        Schema::create('meetup_booth_votes', function (Blueprint $table) {
            $table->id();
            $table->string('event_id');
            $table->foreignId('booth_id')->constrained('meetup_booths')->cascadeOnDelete();
            $table->string('participant_slug');
            $table->timestamp('voted_at');
            $table->timestamps();

            $table->foreign('event_id')->references('id')->on('meetup_events')->cascadeOnDelete();
            $table->unique(['booth_id', 'participant_slug']);
            $table->index(['event_id', 'booth_id']);
        });
    }

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

        Schema::table('meetup_booths', function (Blueprint $table) {
            $table->dropColumn('voting_enabled');
        });
    }
};
