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

use Ferienpass\CoreBundle\Entity\Attendance;
use Ferienpass\CoreBundle\Message\AccountActivated;
use Ferienpass\CoreBundle\Message\AccountAlreadyExists;
use Ferienpass\CoreBundle\Message\AccountDisabled;
use Ferienpass\CoreBundle\Message\ApplicationsClosed;
use Ferienpass\CoreBundle\Message\DeleteUserAccount;
use Ferienpass\CoreBundle\Message\ExportOffers;
use Ferienpass\CoreBundle\Message\GenerateImage;
use Ferienpass\CoreBundle\Message\LotOffer;
use Ferienpass\CoreBundle\Message\OfferCompleteNotify;
use Ferienpass\CoreBundle\Message\OfferFinalized;
use Ferienpass\CoreBundle\Message\RemindAttendance;
use Ferienpass\CoreBundle\Message\SendMailing;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Lock\Key;

final class SimpleMessagesTest extends TestCase
{
    public function testAccountActivatedGetters(): void
    {
        $msg = new AccountActivated('11');

        self::assertSame('11', $msg->getUserUuid());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testAccountAlreadyExistsGetters(): void
    {
        $msg = new AccountAlreadyExists('22');

        self::assertSame('22', $msg->getUserUuid());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testAccountDisabledGetters(): void
    {
        $msg = new AccountDisabled('33');

        self::assertSame('33', $msg->getUserUuid());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testApplicationsClosedGetters(): void
    {
        $msg = new ApplicationsClosed('5');

        self::assertSame('5', $msg->getOfferId());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testDeleteUserAccountGetters(): void
    {
        $msg = new DeleteUserAccount('44');

        self::assertSame('44', $msg->getUserId());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testOfferCompleteNotifyGetters(): void
    {
        $msg = new OfferCompleteNotify('7');

        self::assertSame('7', $msg->getOfferId());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testOfferFinalizedGetters(): void
    {
        $msg = new OfferFinalized('8');

        self::assertSame('8', $msg->getOfferId());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testRemindAttendanceGetters(): void
    {
        $msg = new RemindAttendance('55', '66');

        self::assertSame(['55', '66'], $msg->getAttendanceIds());
        self::assertSame([Attendance::class => ['55', '66']], $msg->getRelated());
    }

    public function testGenerateImageGetters(): void
    {
        $msg = new GenerateImage('Draw a sunny beach', 'job-abc', '10', '20');

        self::assertSame('Draw a sunny beach', $msg->getPrompt());
        self::assertSame('job-abc', $msg->getJobId());
        self::assertSame('10', $msg->getOfferId());
        self::assertSame('20', $msg->getUserId());
    }

    public function testGenerateImageOptionalNulls(): void
    {
        $msg = new GenerateImage('Prompt', 'job-xyz');

        self::assertNull($msg->getOfferId());
        self::assertNull($msg->getUserId());
    }

    public function testExportOffersGetters(): void
    {
        $msg = new ExportOffers('pdf', ['uuid-1', 'uuid-2'], 'user@example.com');

        self::assertSame('pdf', $msg->getExporter());
        self::assertSame(['uuid-1', 'uuid-2'], $msg->getOfferUuids());
        self::assertSame('user@example.com', $msg->getRecipient());
    }

    public function testSendMailingGetters(): void
    {
        $msg = new SendMailing('a@b.com', 'Hello', 'Body text', ['key' => 'val'], ['att.pdf']);

        self::assertSame('a@b.com', $msg->getEmail());
        self::assertSame('Hello', $msg->getSubject());
        self::assertSame('Body text', $msg->getContent());
        self::assertSame(['key' => 'val'], $msg->getContext());
        self::assertSame(['att.pdf'], $msg->getAttachments());
        self::assertNull($msg->getPayment());
    }

    public function testSendMailingGroupedByReturnsNullStringWhenNoGroupId(): void
    {
        $msg = new SendMailing('a@b.com', 'Hi', 'Body', []);

        self::assertSame('', $msg->groupedBy());
    }

    public function testLotOfferGetters(): void
    {
        $key = new Key('lock-resource');
        $msg = new LotOffer('42', $key, false);

        self::assertSame('42', $msg->getOfferId());
        self::assertSame($key, $msg->getKey());
        self::assertFalse($msg->shouldUseWaitlist());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testLotOfferDefaultsToUseWaitlist(): void
    {
        $key = new Key('lock-resource');
        $msg = new LotOffer('10', $key);

        self::assertTrue($msg->shouldUseWaitlist());
    }
}
