<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Marketing;

use CpCreation\VitiCore\Cart\Model\Cart;
use CpCreation\VitiCore\Cart\Model\DeliveryAddress;
use CpCreation\VitiCore\Marketing\ReviewAuthorDisplayNameFormatter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class ReviewAuthorDisplayNameFormatterTest extends TestCase
{
    #[DataProvider('provideNames')]
    public function testFormatsTheOrderIdentityWithoutExposingTheFullLastName(
        ?string $firstname,
        ?string $lastname,
        string $expected,
    ): void {
        $cart = new Cart();
        $address = new DeliveryAddress();
        $address->setFirstname($firstname);
        $address->setLastname($lastname);
        $cart->setDeliveryAddress($address);

        self::assertSame(
            $expected,
            new ReviewAuthorDisplayNameFormatter()->format($cart, 'Client vérifié'),
        );
    }

    /** @return iterable<string, array{?string, ?string, string}> */
    public static function provideNames(): iterable
    {
        yield 'prénom et initiale' => ['  pierre ', ' dupont ', 'Pierre D.'];
        yield 'accents préservés' => ['ÉLODIE', 'd’ARC', 'Élodie D.'];
        yield 'prénom seul' => ['Pierre', null, 'Pierre'];
        yield 'nom seul' => [null, 'Dupont', 'D.'];
        yield 'identité absente' => [null, null, 'Client vérifié'];
    }
}
