<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('event_claims', function (Blueprint $table) {
            $table->id();
            $table->foreignId('event_id')->constrained()->onDelete('cascade');
            $table->integer('user_id');                 // User who is eligible (e.g., user #100)
            $table->integer('role_id')->nullable();     // Character that receives the reward
            $table->string('role_name')->nullable();
            $table->timestamp('claimed_at')->nullable();
            $table->boolean('mail_sent')->default(false);
            $table->timestamps();

            $table->unique(['event_id', 'user_id']);    // One claim per user per event
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('event_claims');
    }
};
