<?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::table('personal_access_tokens', function (Blueprint $table): void {
            $table->string('token_hint', 16)->nullable()->after('token');
            $table->timestamp('revoked_at')->nullable()->after('expires_at');
            $table->index(['tokenable_type', 'tokenable_id', 'revoked_at', 'expires_at'], 'pat_earn_active_idx');
        });
    }

    public function down(): void
    {
        Schema::table('personal_access_tokens', function (Blueprint $table): void {
            $table->dropIndex('pat_earn_active_idx');
            $table->dropColumn(['token_hint', 'revoked_at']);
        });
    }
};
