<?php
declare(strict_types=1);
namespace App\Component\ExternalIntegration\Integration\Tigris;
use App\Component\ExternalIntegration\Integration\Tigris\Configuration\ConfigEnum;
use App\Component\ExternalIntegration\Manager\ExternalVacancyCreated;
use App\Component\ExternalIntegration\Manager\ExternalVacancyUpdated;
use App\Writer\TigrisWriter;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\Event;
class ExposeVacancyToTigrisOnExternalVacancyUperted implements EventSubscriberInterface
{
public function __construct(
private readonly TigrisWriter $tigrisWriter
) {
}
public static function getSubscribedEvents(): array
{
return [
ExternalVacancyCreated::class => 'exposeOnCreate',
ExternalVacancyUpdated::class => 'exposeOnUpdate',
];
}
public function exposeOnCreate(ExternalVacancyCreated $event): void
{
$this->expose($event);
}
public function exposeOnUpdate(ExternalVacancyUpdated $event): void
{
$this->expose($event);
}
private function expose(Event $event): void
{
/** @var ExternalVacancyUpdated|ExternalVacancyCreated $event */
$vacancy = $event->getVacancy();
if ($vacancy->getExternalReference() !== ConfigEnum::EXTERNAL_INTEGRATION_REFERENCE->value) {
return;
}
if (null === $vacancy->getExternalId()) {
return;
}
$this->tigrisWriter->exposeVacancyToTigris($vacancy, $event->getTransaction());
}
}