<?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\Message\AccountCreated;
use Ferienpass\CoreBundle\Message\BlockEmail;
use Ferienpass\CoreBundle\Message\CancelOffer;
use Ferienpass\CoreBundle\Message\DeleteAttendance;
use Ferienpass\CoreBundle\Message\DispatchDecisionLetters;
use Ferienpass\CoreBundle\Message\ExportFinished;
use Ferienpass\CoreBundle\Message\FetchPmPaymentStatus;
use Ferienpass\CoreBundle\Message\GeneratePrompt;
use Ferienpass\CoreBundle\Message\OfferCompleted;
use Ferienpass\CoreBundle\Message\PaymentReceiptCreated;
use Ferienpass\CoreBundle\Message\RelaunchOffer;
use Ferienpass\CoreBundle\Message\SyncOfferVariants;
use Ferienpass\CoreBundle\Message\UnblockEmail;
use Ferienpass\CoreBundle\Message\UpdateParticipantPriorities;
use PHPUnit\Framework\TestCase;

final class MessagesTest extends TestCase
{
    public function testBlockEmailGetEmail(): void
    {
        $msg = new BlockEmail('test@example.com');

        self::assertSame('test@example.com', $msg->getEmail());
    }

    public function testDeleteAttendanceGetAttendanceId(): void
    {
        $msg = new DeleteAttendance('42');

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

    public function testFetchPmPaymentStatusGetTxid(): void
    {
        $msg = new FetchPmPaymentStatus('TX-123');

        self::assertSame('TX-123', $msg->getTxid());
    }

    public function testSyncOfferVariantsGetOfferId(): void
    {
        $msg = new SyncOfferVariants('7');

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

    public function testExportFinishedGetters(): void
    {
        $msg = new ExportFinished('/tmp/export.xlsx', 'user@example.com');

        self::assertSame('/tmp/export.xlsx', $msg->getFile());
        self::assertSame('user@example.com', $msg->getRecipient());
    }

    public function testGeneratePromptGetters(): void
    {
        $msg = new GeneratePrompt('some context', 'job-abc');

        self::assertSame('some context', $msg->getContext());
        self::assertSame('job-abc', $msg->getJobId());
    }

    public function testUpdateParticipantPrioritiesGetters(): void
    {
        $msg = new UpdateParticipantPriorities('5', '10');

        self::assertSame('5', $msg->getParticipantId());
        self::assertSame('10', $msg->getEditionId());
    }

    public function testAccountCreatedGetters(): void
    {
        $msg = new AccountCreated('7', 'myhost');

        self::assertSame('7', $msg->getUserUuid());
        self::assertSame('myhost', $msg->getHost());
        self::assertArrayHasKey(\Ferienpass\CoreBundle\Entity\User::class, $msg->getRelated());
    }

    public function testAccountCreatedDefaultHost(): void
    {
        $msg = new AccountCreated('7');

        self::assertNull($msg->getHost());
    }

    public function testCancelOfferGetters(): void
    {
        $msg = new CancelOffer('3', 'We are sorry.');

        self::assertSame('3', $msg->getOfferId());
        self::assertSame('We are sorry.', $msg->getNotifyText());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testDispatchDecisionLettersGetters(): void
    {
        $msg = new DispatchDecisionLetters('1', ['10', '20', '30']);

        self::assertSame('1', $msg->getEditionId());
        self::assertSame(['10', '20', '30'], $msg->getAttendanceIds());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testOfferCompletedGetters(): void
    {
        $msg = new OfferCompleted('5', ['rating' => 4]);

        self::assertSame('5', $msg->getOfferId());
        self::assertSame(['rating' => 4], $msg->getSurveyData());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testPaymentReceiptCreatedGetters(): void
    {
        $msg = new PaymentReceiptCreated('id-123');

        self::assertSame('id-123', $msg->getPaymentUuid());
        self::assertTrue($msg->shouldNotify());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testPaymentReceiptCreatedNoNotify(): void
    {
        $msg = new PaymentReceiptCreated('id-456', false);

        self::assertFalse($msg->shouldNotify());
    }

    public function testRelaunchOfferGetters(): void
    {
        $msg = new RelaunchOffer('8', 'We are back!');

        self::assertSame('8', $msg->getOfferId());
        self::assertSame('We are back!', $msg->getNotifyText());
        self::assertNotEmpty($msg->getRelated());
    }

    public function testUnblockEmailGetters(): void
    {
        $msg = new UnblockEmail('user@example.com', '42');

        self::assertSame('user@example.com', $msg->getEmail());
        self::assertSame('42', $msg->getUserId());
        self::assertNotEmpty($msg->getRelated());
    }
}
