<?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('contest_winners', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(\App\Models\Contest::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(\App\Models\User::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(\App\Models\ContestParticipant::class, 'participant_id')
                ->nullable()
                ->constrained('contest_participants')
                ->nullOnDelete(); // Nullable if the winner is not a participant
            $table->string('prize_name')->nullable(); // Name of the prize won
            $table->decimal('prize_amount', 10, 2)->default(0.00); // Amount of the prize, if applicable
            $table->integer('rank')->default(0)
                ->comment('Rank of the winner in the contest, e.g., 1 for first place, 2 for second place, etc.');
            $table->timestamps();
        });
    }

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