<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Backs the /linkucp in-game flow: a player generates a short code on their
 * UCP Profile page (Player\ProfileController — see the "link" action) and
 * enters it in-game; the resource then POSTs the code + their FiveM
 * license to routes/api.php so LinkAccountController can attach
 * users.fivem_license without ever trusting a client-supplied user ID.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::create('link_codes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('code', 8)->unique();
            $table->timestamp('expires_at');
            $table->timestamps();
        });
    }

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