<?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\DbafsAttachment;
use Ferienpass\CoreBundle\Entity\Edition;
use Ferienpass\CoreBundle\Entity\Notification;
use PHPUnit\Framework\TestCase;

final class NotificationTest extends TestCase
{
    public function testGetIdIsNullByDefault(): void
    {
        $notification = new Notification('account_created');

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

    public function testGetTypeReturnsType(): void
    {
        $notification = new Notification('account_created');

        self::assertSame('account_created', $notification->getType());
    }

    public function testGetCreatedAtIsSetOnConstruct(): void
    {
        $notification = new Notification('test');

        self::assertInstanceOf(\DateTimeInterface::class, $notification->getCreatedAt());
    }

    public function testGetModifiedAtIsSetOnConstruct(): void
    {
        $notification = new Notification('test');

        self::assertInstanceOf(\DateTimeInterface::class, $notification->getModifiedAt());
    }

    public function testSetModifiedAtUpdatesTimestamp(): void
    {
        $notification = new Notification('test');
        $ts = new \DateTimeImmutable('2024-06-01 10:00:00');
        $notification->setModifiedAt($ts);

        self::assertSame($ts, $notification->getModifiedAt());
    }

    public function testSetModifiedAtUsesNowWhenNullPassed(): void
    {
        $notification = new Notification('test');
        $before = new \DateTimeImmutable();
        $notification->setModifiedAt(null);
        $after = new \DateTimeImmutable();

        self::assertGreaterThanOrEqual($before, $notification->getModifiedAt());
        self::assertLessThanOrEqual($after, $notification->getModifiedAt());
    }

    public function testGetEmailSubjectIsNullByDefault(): void
    {
        $notification = new Notification('test');

        self::assertNull($notification->getEmailSubject());
    }

    public function testSetEmailSubjectAndGetIt(): void
    {
        $notification = new Notification('test');
        $notification->setEmailSubject('Hello World');

        self::assertSame('Hello World', $notification->getEmailSubject());
    }

    public function testGetEmailReplyToIsNullByDefault(): void
    {
        $notification = new Notification('test');

        self::assertNull($notification->getEmailReplyTo());
    }

    public function testSetEmailReplyToAndGetIt(): void
    {
        $notification = new Notification('test');
        $notification->setEmailReplyTo('reply@example.com');

        self::assertSame('reply@example.com', $notification->getEmailReplyTo());
    }

    public function testGetEmailToIsNullByDefault(): void
    {
        $notification = new Notification('test');

        self::assertNull($notification->getEmailTo());
    }

    public function testSetEmailToAndGetIt(): void
    {
        $notification = new Notification('test');
        $notification->setEmailTo('to@example.com');

        self::assertSame('to@example.com', $notification->getEmailTo());
    }

    public function testGetEmailTextIsNullByDefault(): void
    {
        $notification = new Notification('test');

        self::assertNull($notification->getEmailText());
    }

    public function testSetEmailTextAndGetIt(): void
    {
        $notification = new Notification('test');
        $notification->setEmailText('Hello, this is the email body.');

        self::assertSame('Hello, this is the email body.', $notification->getEmailText());
    }

    public function testGetSmsTextIsNullByDefault(): void
    {
        $notification = new Notification('test');

        self::assertNull($notification->getSmsText());
    }

    public function testSetSmsTextAndGetIt(): void
    {
        $notification = new Notification('test');
        $notification->setSmsText('SMS body');

        self::assertSame('SMS body', $notification->getSmsText());
    }

    public function testIsDisabledReturnsFalseByDefault(): void
    {
        $notification = new Notification('test');

        self::assertFalse($notification->isDisabled());
    }

    public function testSetDisabledUpdatesValue(): void
    {
        $notification = new Notification('test');
        $notification->setDisabled(true);

        self::assertTrue($notification->isDisabled());
    }

    public function testGetEditionIsNullByDefault(): void
    {
        $notification = new Notification('test');

        self::assertNull($notification->getEdition());
    }

    public function testSetEditionAndGetEdition(): void
    {
        $notification = new Notification('test');
        $edition = new Edition();
        $notification->setEdition($edition);

        self::assertSame($edition, $notification->getEdition());
    }

    public function testConstructWithEdition(): void
    {
        $edition = new Edition();
        $notification = new Notification('test', $edition);

        self::assertSame($edition, $notification->getEdition());
    }

    public function testGetAndSetEmailAttachment(): void
    {
        $notification = new Notification('test');
        $attachment = new DbafsAttachment();
        $notification->setEmailAttachment($attachment);

        self::assertSame($attachment, $notification->getEmailAttachment());
    }
}
