<?php

use App\Models\Operator;
use Illuminate\Support\Facades\Auth;

it('authenticates on its own guard, not on web', function () {
    $operator = Operator::factory()->create(['password' => 'geheim-genug-12']);

    expect(Auth::guard('operator')->attempt([
        'email' => $operator->email, 'password' => 'geheim-genug-12',
    ]))->toBeTrue();

    // The web guard resolves against users, which has no such row.
    expect(Auth::guard('web')->attempt([
        'email' => $operator->email, 'password' => 'geheim-genug-12',
    ]))->toBeFalse();
});

it('hashes the password rather than storing it', function () {
    $operator = Operator::factory()->create(['password' => 'geheim-genug-12']);

    expect($operator->password)->not->toBe('geheim-genug-12')
        ->and(Hash::check('geheim-genug-12', $operator->password))->toBeTrue();
});

it('assigns a uuid on create and uses it as the route key', function () {
    $operator = Operator::factory()->create();

    expect($operator->uuid)->not->toBeNull()
        ->and($operator->getRouteKeyName())->toBe('uuid');
});

it('carries the two-factor columns Fortify expects', function () {
    $operator = Operator::factory()->create();

    expect($operator->two_factor_secret)->toBeNull()
        ->and($operator->two_factor_confirmed_at)->toBeNull()
        ->and(method_exists($operator, 'twoFactorQrCodeSvg'))->toBeTrue();
});

it('can be disabled without deleting the record', function () {
    $operator = Operator::factory()->create(['disabled_at' => now()]);

    expect($operator->fresh()->disabled_at)->not->toBeNull();
});
