<?php

declare(strict_types=1);

namespace Apexl\Tests\User\UnitTests;

use apexl\Io\modules\user\enums\TwoFactorMode;
use apexl\Io\TestInfrastructure\UnitTest;
use PHPUnit\Framework\Attributes\Test;

final class TwoFactorModeTest extends UnitTest
{
    #[Test]
    public function mapsKnownValues(): void
    {
        $this->assertSame(TwoFactorMode::OFF, TwoFactorMode::fromConfigValue('off'));
        $this->assertSame(TwoFactorMode::OPTIONAL, TwoFactorMode::fromConfigValue('optional'));
        $this->assertSame(TwoFactorMode::ENFORCED, TwoFactorMode::fromConfigValue('enforced'));
        $this->assertSame(TwoFactorMode::OPTIONAL, TwoFactorMode::fromConfigValue(' OPTIONAL '));
    }

    /**
     * A mis-set, empty, or non-string mode must fall back to OFF — enforcement
     * can never be accidentally enabled by a bad env value.
     */
    #[Test]
    public function unknownOrEmptyDefaultsToOff(): void
    {
        $this->assertSame(TwoFactorMode::OFF, TwoFactorMode::fromConfigValue('nonsense'));
        $this->assertSame(TwoFactorMode::OFF, TwoFactorMode::fromConfigValue(''));
        $this->assertSame(TwoFactorMode::OFF, TwoFactorMode::fromConfigValue(null));
        $this->assertSame(TwoFactorMode::OFF, TwoFactorMode::fromConfigValue(123));
        $this->assertTrue(TwoFactorMode::OFF->isOff());
        $this->assertFalse(TwoFactorMode::ENFORCED->isOff());
    }
}
