<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Cart\LegacyOrderImport;

use CpCreation\VitiCore\Cart\LegacyOrderImport\LegacyAddressNormalizer;
use PHPUnit\Framework\TestCase;

final class LegacyAddressNormalizerTest extends TestCase
{
    private LegacyAddressNormalizer $normalizer;

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

    public function testNormalizesCommonInternationalPhoneNotations(): void
    {
        self::assertSame('+33326000000', $this->normalizer->phone('+33 (0)3 26 00 00 00'));
        self::assertSame('+33326000000', $this->normalizer->phone('0033 3 26 00 00 00'));
    }

    public function testTruncatesHistoricalFreeTextToTheExistingPhoneColumn(): void
    {
        self::assertSame('non communiq', $this->normalizer->phone(' non communique '));
        self::assertSame('++33 3 26', $this->normalizer->phone('++33 3 26'));
    }

    public function testNormalizesAndTruncatesAVatIdentifierToTheExistingColumn(): void
    {
        self::assertSame(
            'FR12345678901234',
            $this->normalizer->vatId('fr 12-3456-7890-1234-5678-9012-3456-7890-12345'),
        );
    }

    public function testTruncatesValuesLongerThanTheExistingSchema(): void
    {
        self::assertSame(str_repeat('1', 12), $this->normalizer->phone(str_repeat('1', 65)));
        self::assertSame(str_repeat('A', 16), $this->normalizer->vatId(str_repeat('a', 65)));
        self::assertSame(12, LegacyAddressNormalizer::MAX_PHONE_LENGTH);
        self::assertSame(16, LegacyAddressNormalizer::MAX_VAT_ID_LENGTH);
    }
}
