<?php

declare(strict_types=1);

namespace Ferienpass\AdminBundle\Tests\NotificationHandler;

use Ferienpass\AdminBundle\Message\HostInvited;
use Ferienpass\AdminBundle\NotificationHandler\HostInvitation;
use Ferienpass\CoreBundle\Notifier\Notifier;
use Ferienpass\CoreBundle\Repository\HostRepository;
use Ferienpass\CoreBundle\Repository\UserRepository;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\UriSigner;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Uid\Uuid;

final class HostInvitationTest extends TestCase
{
    public function testDoesNothingWhenUserNotFound(): void
    {
        $users = $this->createMock(UserRepository::class);
        $users->method('findOneBy')->willReturn(null);

        $hosts = $this->createMock(HostRepository::class);

        $notifier = $this->createMock(Notifier::class);
        $notifier->expects(self::never())->method('send');

        $handler = new HostInvitation(
            $notifier,
            $hosts,
            $users,
            $this->createMock(UrlGeneratorInterface::class),
            $this->createMock(UriSigner::class)
        );
        $handler(new HostInvited('invitee@example.com', Uuid::v7()->toRfc4122(), Uuid::v7()->toRfc4122()), Uuid::v7());
    }

    public function testDoesNothingWhenHostNotFound(): void
    {
        $user = new \Ferienpass\CoreBundle\Entity\User();

        $users = $this->createMock(UserRepository::class);
        $users->method('findOneBy')->willReturn($user);

        $hosts = $this->createMock(HostRepository::class);
        $hosts->method('findOneBy')->willReturn(null);

        $notifier = $this->createMock(Notifier::class);
        $notifier->expects(self::never())->method('send');

        $handler = new HostInvitation(
            $notifier,
            $hosts,
            $users,
            $this->createMock(UrlGeneratorInterface::class),
            $this->createMock(UriSigner::class)
        );
        $handler(new HostInvited('invitee@example.com', Uuid::v7()->toRfc4122(), Uuid::v7()->toRfc4122()), Uuid::v7());
    }

    public function testDoesNothingWhenNotifierReturnsNull(): void
    {
        $user = new \Ferienpass\CoreBundle\Entity\User();
        $host = new \Ferienpass\CoreBundle\Entity\Host();

        $users = $this->createMock(UserRepository::class);
        $users->method('findOneBy')->willReturn($user);

        $hosts = $this->createMock(HostRepository::class);
        $hosts->method('findOneBy')->willReturn($host);

        $notifier = $this->createMock(Notifier::class);
        $notifier->method('userInvitation')->willReturn(null);
        $notifier->expects(self::never())->method('send');

        $handler = new HostInvitation(
            $notifier,
            $hosts,
            $users,
            $this->createMock(UrlGeneratorInterface::class),
            $this->createMock(UriSigner::class)
        );
        $handler(new HostInvited('invitee@example.com', Uuid::v7()->toRfc4122(), Uuid::v7()->toRfc4122()), Uuid::v7());
    }
}
