<?php

use App\Models\User;

it('enables 2FA and returns recovery codes', function () {
    $user = User::factory()->create();

    $codes = $user->enableTwoFactor('JBSWY3DPEHPK3PXP');

    expect($codes)->toHaveCount(8)
        ->and($user->fresh()->two_factor_secret)->not->toBeNull();
});

it('disables 2FA and clears secrets', function () {
    $user = User::factory()->create();
    $user->enableTwoFactor('JBSWY3DPEHPK3PXP');

    $user->disableTwoFactor();

    $fresh = $user->fresh();
    expect($fresh->two_factor_secret)->toBeNull()
        ->and($fresh->two_factor_confirmed_at)->toBeNull();
});

it('reports 2FA as disabled before confirmation', function () {
    $user = User::factory()->create();
    $user->enableTwoFactor('JBSWY3DPEHPK3PXP');

    // two_factor_confirmed_at is null → hasTwoFactorEnabled() = false
    expect($user->fresh()->hasTwoFactorEnabled())->toBeFalse();
});
