<?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('evento_jugador', function (Blueprint $table) {
            $table->id();
            $table->string('id_evento');
            $table->string('id_jugador');
            $table->integer('puntos')->default(0);
            $table->integer('faltas')->default(0);
            $table->timestamps();

            $table->foreign('id_evento')->references('id_evento')->on('eventos')->onDelete('cascade');
            $table->foreign('id_jugador')->references('id_jugador')->on('jugadores')->onDelete('cascade');
            
            // Un jugador solo puede tener un registro de puntos por evento
            $table->unique(['id_evento', 'id_jugador']);
        });
    }

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