<?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('matchmaking_queue', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->integer('elo_snapshot');
            $table->string('region')->default('global');
            // searching | matched | cancelled
            $table->string('status')->default('searching');
            $table->foreignId('match_id')->nullable()->constrained('matches')->nullOnDelete();
            $table->timestamp('joined_at')->useCurrent();
            $table->timestamps();

            $table->index(['status', 'elo_snapshot']);
            $table->unique('user_id');
        });
    }

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