<?php

namespace App\Tests\Service\Generator;

use App\Service\Generator\TempPasswordGenerator;
use PHPUnit\Framework\TestCase;

class TempPasswordGeneratorTest extends TestCase
{
    public function testGenerateDefaultLength(): void
    {
        $password = TempPasswordGenerator::generate();
        $this->assertEquals(12, strlen($password));
    }

    public function testGenerateCustomLength(): void
    {
        $length = 16;
        $password = TempPasswordGenerator::generate($length);
        $this->assertEquals($length, strlen($password));
    }

    public function testGenerateInvalidLength(): void
    {
        $password = TempPasswordGenerator::generate(-5);
        $this->assertEquals(12, strlen($password)); // Should fallback to default
    }

    public function testGenerateCustomCharacters(): void
    {
        $chars = 'ABC';
        $password = TempPasswordGenerator::generate(10, $chars);
        $this->assertEquals(10, strlen($password));
        $this->assertMatchesRegularExpression('/^[ABC]+$/', $password);
    }

    public function testIsComplexValid(): void
    {
        // Needs 8+ chars, Upper, Lower, Digit, Special
        $password = 'Ab1!defg'; 
        $this->assertTrue(TempPasswordGenerator::isComplex($password));
    }

    public function testIsComplexTooShort(): void
    {
        $password = 'Ab1!de'; // 6 chars
        $this->assertFalse(TempPasswordGenerator::isComplex($password));
    }

    public function testIsComplexMissingUpper(): void
    {
        $password = 'ab1!defg';
        $this->assertFalse(TempPasswordGenerator::isComplex($password));
    }

    public function testIsComplexMissingLower(): void
    {
        $password = 'AB1!DEFG';
        $this->assertFalse(TempPasswordGenerator::isComplex($password));
    }

    public function testIsComplexMissingDigit(): void
    {
        $password = 'Abc!defg';
        $this->assertFalse(TempPasswordGenerator::isComplex($password));
    }

    public function testIsComplexMissingSpecial(): void
    {
        $password = 'Ab12defg';
        $this->assertFalse(TempPasswordGenerator::isComplex($password));
    }
}
