<?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('football_matches', function (Blueprint $table) {
            $table->id();
            $table->foreignId('home_team_id')->constrained('teams')->restrictOnDelete();
            $table->foreignId('away_team_id')->constrained('teams')->restrictOnDelete();
            $table->dateTime('match_datetime');
            $table->string('venue')->nullable();
            $table->enum('stage', [
                'group', 'round_of_16', 'quarterfinal', 'semifinal', 'final'
            ])->default('group');
            $table->string('group_name', 1)->nullable();   // "A" .. "H"
            $table->enum('status', ['upcoming', 'live', 'finished'])->default('upcoming');
            $table->unsignedTinyInteger('home_score')->nullable();
            $table->unsignedTinyInteger('away_score')->nullable();
            // Community prediction vote counts (admin can update these)
            $table->unsignedInteger('home_community_votes')->default(0);
            $table->unsignedInteger('away_community_votes')->default(0);
            $table->unsignedInteger('draw_community_votes')->default(0);
            $table->timestamps();
        });
    }

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