<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Tests\NotificationHandler;

use Ferienpass\CoreBundle\NotificationHandler\PhoneFormatter;
use PHPUnit\Framework\TestCase;

final class PhoneFormatterTest extends TestCase
{
    private PhoneFormatter $formatter;

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

    public function testFormatNullReturnsNull(): void
    {
        self::assertNull($this->formatter->format(null));
    }

    public function testFormatEmptyStringReturnsNull(): void
    {
        self::assertNull($this->formatter->format(''));
    }

    public function testFormatValidGermanNumber(): void
    {
        $result = $this->formatter->format('+49 30 12345678');

        // E164 format: +493012345678, strip + → 493012345678
        self::assertSame('493012345678', $result);
    }

    public function testFormatWithStripPlusFalse(): void
    {
        $result = $this->formatter->format('+49 30 12345678', false);

        // E164 format with + kept
        self::assertSame('+493012345678', $result);
    }

    public function testFormatInvalidNumberReturnsNull(): void
    {
        $result = $this->formatter->format('not-a-phone-number');

        self::assertNull($result);
    }

    public function testFormatGermanLocalNumberWithDefaultRegion(): void
    {
        $result = $this->formatter->format('030 12345678');

        self::assertNotNull($result);
        // Should contain German country code in E164 format without +
        self::assertStringContainsString('493012345678', $result);
    }
}
