<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Marketing;

use CpCreation\VitiCore\Marketing\Model\ReviewSolicitationOptOut;
use PHPUnit\Framework\TestCase;

final class ReviewSolicitationOptOutTest extends TestCase
{
    public function testItStoresOnlyANormalizedEmailHash(): void
    {
        $optOut = new ReviewSolicitationOptOut('  CLIENT@EXAMPLE.COM ');

        self::assertSame(64, \strlen($optOut->getEmailHash()));
        self::assertNotSame('client@example.com', $optOut->getEmailHash());
        self::assertTrue($optOut->matches('client@example.com'));
        self::assertTrue($optOut->matches(' CLIENT@EXAMPLE.COM '));
        self::assertFalse($optOut->matches('other@example.com'));
    }

    public function testItRejectsAnInvalidEmailAddress(): void
    {
        $this->expectException(\InvalidArgumentException::class);

        new ReviewSolicitationOptOut('not-an-email');
    }
}
