<?php

declare(strict_types=1);

namespace App\Tests\Module\Commercial\Unit;

use App\Module\Commercial\Application\Service\ClientFieldNormalizer;
use PHPUnit\Framework\TestCase;

/**
 * Tests unitaires de la normalisation serveur (RG-1.18 a RG-1.21).
 *
 * @internal
 */
final class ClientFieldNormalizerTest extends TestCase
{
    private ClientFieldNormalizer $normalizer;

    protected function setUp(): void
    {
        $this->normalizer = new ClientFieldNormalizer();
    }

    public function testCompanyNameIsUppercased(): void
    {
        // RG-1.18
        self::assertSame('ACME SAS', $this->normalizer->normalizeCompanyName('  acme sas '));
        self::assertNull($this->normalizer->normalizeCompanyName(null));
    }

    public function testPersonNameIsTitleCased(): void
    {
        // RG-1.19
        self::assertSame('Jean', $this->normalizer->normalizePersonName('JEAN'));
        self::assertSame('Dupont', $this->normalizer->normalizePersonName('dupont'));
        self::assertNull($this->normalizer->normalizePersonName('   '));
        self::assertNull($this->normalizer->normalizePersonName(null));
    }

    public function testEmailIsLowercased(): void
    {
        // RG-1.21
        self::assertSame('jean.dupont@acme.fr', $this->normalizer->normalizeEmail(' Jean.DUPONT@ACME.FR '));
        self::assertNull($this->normalizer->normalizeEmail(null));
        self::assertNull($this->normalizer->normalizeEmail('   '));
    }

    public function testPhoneKeepsOnlyDigits(): void
    {
        // RG-1.20
        self::assertSame('0612345678', $this->normalizer->normalizePhone('06.12.34.56.78'));
        self::assertSame('0612345678', $this->normalizer->normalizePhone('06 12 34 56 78'));
        self::assertNull($this->normalizer->normalizePhone('----'));
        self::assertNull($this->normalizer->normalizePhone(null));
    }
}
