<?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('clubs', function (Blueprint $table) {
            $table->id();
            $table->string('name');                        // Full name: "FC Barcelona"
            $table->string('short_name', 10)->nullable();  // "BAR"
            $table->string('logo')->nullable();            // path to logo image
            $table->string('nationality')->nullable();     // "Spain"
            $table->unsignedSmallInteger('overall')->default(80); // overall rating
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        // Ban records per series (once per encounter, applies to all legs)
        Schema::create('tournament_match_bans', function (Blueprint $table) {
            $table->id();
            // Points to the series root (leg_number=1) match
            $table->foreignId('series_root_id')->constrained('tournament_matches')->cascadeOnDelete();
            // Which player is doing the banning
            $table->foreignId('player_id')->constrained('users')->cascadeOnDelete();
            // The club being banned
            $table->foreignId('club_id')->constrained('clubs')->cascadeOnDelete();
            $table->timestamps();

            $table->unique(['series_root_id', 'player_id', 'club_id']);
        });
    }

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