<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\SentEmail;
use Ferienpass\CoreBundle\Notifier\Mime\NotificationEmail;
use PHPUnit\Framework\TestCase;

final class SentEmailTest extends TestCase
{
    public function testFromNotificationEmailStoresBasicData(): void
    {
        $email = new NotificationEmail('test_type');
        $email->from('sender@example.com');
        $email->to('recipient@example.com');
        $email->subject('Test Subject');
        $email->text('Hello text');
        $email->html('<p>Hello html</p>');

        $entity = SentEmail::fromNotificationEmail($email, 'msg-id-123');

        self::assertSame('msg-id-123', $entity->getMessageId());
        self::assertSame('sender@example.com', $entity->getFrom());
        self::assertSame('recipient@example.com', $entity->getTo());
        self::assertSame('Test Subject', $entity->getSubject());
        self::assertSame('Hello text', $entity->getText());
        self::assertSame('<p>Hello html</p>', $entity->getHtml());
        self::assertSame([], $entity->getAttachments());
    }

    public function testFromNotificationEmailWithNoAddresses(): void
    {
        $email = new NotificationEmail('welcome');

        $entity = SentEmail::fromNotificationEmail($email, 'msg-xyz');

        self::assertNull($entity->getFrom());
        self::assertNull($entity->getTo());
        self::assertNull($entity->getSubject());
    }
}
