<?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('users', function (Blueprint $table) {
            $table->timestamp('user_jwt_issued_at')->nullable()->after('user_jwt');
            $table->timestamp('user_jwt_expires_at')->nullable()->after('user_jwt_issued_at');

            // Tracks privilege changes. Increment this whenever privileges/roles change.
            $table->unsignedBigInteger('privileges_version')->default(1)->after('expiresIn');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'user_jwt_issued_at',
                'user_jwt_expires_at',
                'privileges_version',
            ]);
        });
    }
};