<?php

namespace MintyPHP\Tests\Service\User;

use MintyPHP\Service\User\UserPasswordPolicyService;
use PHPUnit\Framework\TestCase;

class UserPasswordPolicyServiceTest extends TestCase
{
    public function testMinLengthMatchesHints(): void
    {
        $service = new UserPasswordPolicyService();
        $this->assertSame(12, $service->minLength());

        $hints = $service->hints();
        $this->assertNotEmpty($hints);
        $this->assertSame('min', (string) ($hints[0]['rule'] ?? ''));
    }

    public function testValidateRejectsWeakPassword(): void
    {
        $service = new UserPasswordPolicyService();
        $errors = $service->validate('abc', 'abc', true, 'foo@example.com');

        $this->assertNotEmpty($errors);
    }

    public function testValidateRequiresPasswordWhenRequired(): void
    {
        $service = new UserPasswordPolicyService();
        $errors = $service->validate('', '', true, 'test@example.com');

        $this->assertNotEmpty($errors);
    }

    public function testValidateRejectsMismatch(): void
    {
        $service = new UserPasswordPolicyService();
        $errors = $service->validate('Abcd1234$efg', 'Abcd1234$xxx', true, 'test@example.com');

        $this->assertNotEmpty($errors);
    }

    public function testValidateAcceptsStrongPassword(): void
    {
        $service = new UserPasswordPolicyService();
        $errors = $service->validate('StrongPass1!', 'StrongPass1!', true, 'test@example.com');

        $this->assertSame([], $errors);
    }

    public function testValidateRejectsPasswordContainingEmail(): void
    {
        $service = new UserPasswordPolicyService();
        $errors = $service->validate('test@example.comA1!', 'test@example.comA1!', true, 'test@example.com');

        $this->assertNotEmpty($errors);
    }
}
