<?php
namespace Harmonizely\Service\Panel\Api\SmsGateway\EventSubscriber;
use Harmonizely\CalendarEvents;
use Harmonizely\Model\Event;
use Harmonizely\Service\Panel\Api\SmsGateway\Contract\ISendSmsForEventTemplate;
use Harmonizely\Types\SmsTemplateType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class SendSmsSubscriber implements EventSubscriberInterface
{
/**
* @var ISendSmsForEventTemplate
*/
private ISendSmsForEventTemplate $sendSmsForEventTemplate;
/**
* @param ISendSmsForEventTemplate $sendSmsForEventTemplate
*/
public function __construct(ISendSmsForEventTemplate $sendSmsForEventTemplate)
{
$this->sendSmsForEventTemplate = $sendSmsForEventTemplate;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
CalendarEvents::EVENT_POST_CREATE => 'create',
CalendarEvents::EVENT_POST_RESCHEDULE => 'reschedule',
CalendarEvents::EVENT_POST_CANCEL => 'cancel',
];
}
/**
* @param GenericEvent $genericEvent
* @return void
*/
public function create(GenericEvent $genericEvent): void
{
/** @var Event $event */
$event = $genericEvent->getSubject();
$this->sendSmsForEventTemplate->perform($event, SmsTemplateType::TYPE_EVENT_SCHEDULED);
}
/**
* @param GenericEvent $genericEvent
* @return void
*/
public function reschedule(GenericEvent $genericEvent): void
{
/** @var Event $event */
$event = $genericEvent->getSubject();
$this->sendSmsForEventTemplate->perform($event, SmsTemplateType::TYPE_EVENT_RESCHEDULED);
}
/**
* @param GenericEvent $genericEvent
* @return void
*/
public function cancel(GenericEvent $genericEvent): void
{
/** @var Event $event */
$event = $genericEvent->getSubject();
$this->sendSmsForEventTemplate->perform($event, SmsTemplateType::TYPE_EVENT_CANCELED);
}
}