<?php

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

/**
 * Runs against the `fivem` connection deliberately (see config/fivem.php)
 * — bans/warnings live next to player data on the game server's database,
 * not in the UCP's own `mysql` database, so FiveM Lua resources can read
 * them with a single local oxmysql query.
 */
return new class extends Migration
{
    protected $connection = 'fivem';

    public function up(): void
    {
        Schema::connection('fivem')->create(config('fivem.ucp_tables.bans', 'ucp_bans'), function (Blueprint $table) {
            $table->id();
            $table->string('citizenid')->nullable()->index();
            $table->string('license')->index();
            $table->text('reason');
            $table->string('banned_by');
            $table->timestamp('expires_at')->nullable();
            $table->timestamps();
        });

        Schema::connection('fivem')->create(config('fivem.ucp_tables.warnings', 'ucp_warnings'), function (Blueprint $table) {
            $table->id();
            $table->string('citizenid')->index();
            $table->text('reason');
            $table->string('warned_by');
            $table->timestamp('created_at')->useCurrent();
        });
    }

    public function down(): void
    {
        Schema::connection('fivem')->dropIfExists(config('fivem.ucp_tables.bans', 'ucp_bans'));
        Schema::connection('fivem')->dropIfExists(config('fivem.ucp_tables.warnings', 'ucp_warnings'));
    }
};
