<?php
declare(strict_types=1);
namespace Harmonizely\EventListener;
use Harmonizely\EmailManager\EventEmailManagerInterface;
use Harmonizely\Mailer\AllowedSendingEmailNotificationToInviteePolicy;
use Harmonizely\Model\EventInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;
final class EventRescheduledListener
{
private $eventEmailManager;
private AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy;
public function __construct(
EventEmailManagerInterface $eventEmailManager,
AllowedSendingEmailNotificationToInviteePolicy $allowedSendingEmailNotificationToInviteePolicy
) {
$this->eventEmailManager = $eventEmailManager;
$this->allowedSendingEmailNotificationToInviteePolicy = $allowedSendingEmailNotificationToInviteePolicy;
}
public function sendEmail(GenericEvent $event): void
{
/** @var EventInterface $event */
$event = $event->getSubject();
Assert::isInstanceOf($event, EventInterface::class);
$this->eventEmailManager->sendReschedulingNotify($event);
}
public function sendReschedulingNotifyToInvitee(GenericEvent $event): void
{
/** @var EventInterface $event */
$event = $event->getSubject();
Assert::isInstanceOf($event, EventInterface::class);
if (false === ($this->allowedSendingEmailNotificationToInviteePolicy)($event)) {
return;
}
$this->eventEmailManager->sendReschedulingNotifyToInvitee($event);
}
}