<?php

namespace Tests\Unit;

use App\Domain\Shared\Helpers\CredentialNormalizer;
use PHPUnit\Framework\TestCase;

class CredentialNormalizerTest extends TestCase
{
    public function test_email_is_lowercased_and_trimmed(): void
    {
        $this->assertSame('km97911801@gmail.com', CredentialNormalizer::email('Km97911801@gmail.com'));
        $this->assertSame('a@icloud.com', CredentialNormalizer::email('  A@iCloud.com  '));
    }

    public function test_blank_email_becomes_null(): void
    {
        $this->assertNull(CredentialNormalizer::email(null));
        $this->assertNull(CredentialNormalizer::email('   '));
    }

    public function test_phone_is_reduced_to_local_digits(): void
    {
        $this->assertSame('01141078754', CredentialNormalizer::phone('0 11 41078754'));
        $this->assertSame('01014087672', CredentialNormalizer::phone('+201014087672'));
        $this->assertSame('01027203379', CredentialNormalizer::phone('01027203379'));
    }

    public function test_phone_variants_cover_local_and_international_forms(): void
    {
        $variants = CredentialNormalizer::phoneVariants('01014087672');

        $this->assertContains('01014087672', $variants);
        $this->assertContains('+201014087672', $variants);
        $this->assertContains('201014087672', $variants);
    }

    public function test_local_and_international_input_agree(): void
    {
        $this->assertSame(
            CredentialNormalizer::phone('01014087672'),
            CredentialNormalizer::phone('+20 101 408 7672'),
        );
    }
}
