<?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\Entity;

use Ferienpass\CoreBundle\Entity\SentMessage;
use Ferienpass\CoreBundle\Entity\SentMessageEngagement;
use PHPUnit\Framework\TestCase;

final class SentMessageEngagementTest extends TestCase
{
    public function testGetIdIsNullByDefault(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'open');

        self::assertNull($engagement->getId());
    }

    public function testGetMessageReturnsMessage(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'open');

        self::assertSame($msg, $engagement->getMessage());
    }

    public function testGetEventReturnsEvent(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'click');

        self::assertSame('click', $engagement->getEvent());
    }

    public function testGetTimestampDefaultsToNow(): void
    {
        $msg = new SentMessage();
        $before = new \DateTimeImmutable();
        $engagement = new SentMessageEngagement($msg, 'open');
        $after = new \DateTimeImmutable();

        self::assertGreaterThanOrEqual($before, $engagement->getTimestamp());
        self::assertLessThanOrEqual($after, $engagement->getTimestamp());
    }

    public function testGetTimestampUsesProvidedTimestamp(): void
    {
        $msg = new SentMessage();
        $ts = new \DateTimeImmutable('2024-01-15 10:00:00');
        $engagement = new SentMessageEngagement($msg, 'open', $ts);

        self::assertSame($ts, $engagement->getTimestamp());
    }

    public function testGetReasonIsNullByDefault(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'bounce');

        self::assertNull($engagement->getReason());
    }

    public function testSetReasonUpdatesReason(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'bounce');
        $engagement->setReason('hard_bounce');

        self::assertSame('hard_bounce', $engagement->getReason());
    }

    public function testGetLinkIsNullByDefault(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'click');

        self::assertNull($engagement->getLink());
    }

    public function testSetLinkUpdatesLink(): void
    {
        $msg = new SentMessage();
        $engagement = new SentMessageEngagement($msg, 'click');
        $engagement->setLink('https://example.com');

        self::assertSame('https://example.com', $engagement->getLink());
    }
}
