<?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->boolean('is_active')->default(true)->after('abilities');
            $table->softDeletes()->after('revoked_at');
            $table->index(['tokenable_type', 'tokenable_id', 'deleted_at'], 'pat_owner_deleted_idx');
            $table->index(['is_active', 'revoked_at', 'expires_at'], 'pat_lifecycle_idx');
        });
    }

    public function down(): void
    {
        Schema::table('personal_access_tokens', function (Blueprint $table): void {
            $table->dropIndex('pat_owner_deleted_idx');
            $table->dropIndex('pat_lifecycle_idx');
            $table->dropSoftDeletes();
            $table->dropColumn('is_active');
        });
    }
};
