<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            // 2FA enabled flag (tracking it explicitly for admins)
            $table->boolean('two_factor_enabled')->default(false)->after('email_verified_at');

            // Track if user has completed initial 2FA setup
            $table->timestamp('two_factor_setup_at')->nullable()->after('two_factor_enabled');

            // Index for querying users who need to set up 2FA
            $table->index(['two_factor_enabled', 'two_factor_setup_at']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropIndex(['two_factor_enabled', 'two_factor_setup_at']);
            $table->dropColumn(['two_factor_enabled', 'two_factor_setup_at']);
        });
    }
};
