<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\MessageHandler;

use Doctrine\ORM\EntityManagerInterface;
use Ferienpass\CoreBundle\Message\DispatchMailing as DispatchMailingCommand;
use Ferienpass\CoreBundle\MessageHandler\DispatchMailing;
use Ferienpass\CoreBundle\Repository\AttendanceRepository;
use Ferienpass\CoreBundle\Repository\UserRepository;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

final class DispatchMailingTest extends TestCase
{
    public function testDoesNotDispatchWhenEmailListIsEmpty(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $handler = new DispatchMailing(
            $bus,
            $this->createMock(AttendanceRepository::class),
            $this->createMock(EventDispatcherInterface::class),
            $this->createMock(EntityManagerInterface::class),
            $this->createMock(UserRepository::class),
        );

        $handler(new DispatchMailingCommand(null, [], 'Subject', 'Content', []), Uuid::v7());
    }

    public function testSkipsEmptyStringEmails(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $handler = new DispatchMailing(
            $bus,
            $this->createMock(AttendanceRepository::class),
            $this->createMock(EventDispatcherInterface::class),
            $this->createMock(EntityManagerInterface::class),
            $this->createMock(UserRepository::class),
        );

        $handler(new DispatchMailingCommand(null, ['', ''], 'Subject', 'Content', []), Uuid::v7());
    }
}
