<?php
namespace App\EventListener;
use App\Domain\Event\Identification;
use App\Entity\BankUser;
use App\Repository\BankUserRepository;
use App\Services\Clients\ClientSystemState\ClientSystemStateService;
use App\Services\Clients\Identification\Idenfy\ClientDocumentService;
use App\Services\Clients\Shareholder\ShareholderService;
use App\Services\CommunicationService;
use App\Utils\KafkaNotifier;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class IdentificationListener implements EventSubscriberInterface
{
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var CommunicationService
*/
private $communicationService;
/**
* @var KafkaNotifier
*/
private $kafkaNotifier;
/**
* @var BankUserRepository
*/
private $bankUserRepository;
/**
* @var ClientSystemStateService
*/
private $systemStateService;
/**
* @var ShareholderService
*/
private $shareholderService;
public function __construct(
CommunicationService $communicationService,
LoggerInterface $logger,
KafkaNotifier $kafkaNotifier,
BankUserRepository $bankUserRepository,
ClientSystemStateService $systemStateService,
ShareholderService $shareholderService
) {
$this->communicationService = $communicationService;
$this->logger = $logger;
$this->kafkaNotifier = $kafkaNotifier;
$this->bankUserRepository = $bankUserRepository;
$this->systemStateService = $systemStateService;
$this->shareholderService = $shareholderService;
}
public function processClientSystemState(Identification $event)
{
$client = $event->getClient();
$this->systemStateService->processClientSystemState($client);
$verificationStatus = $event->getVerificationStatus();
if ($client->isPerson()) {
$this->shareholderService->setShareholderState($client->getPerson(), $verificationStatus);
}
}
public function sendSMS(Identification $event)
{
if ($event->getVerificationStatus() == ClientDocumentService::STATUS_APPROVED) {
$client = $event->getClient();
$this->communicationService->sendSmsIfConfirmedIdentifyMessage($client);
}
}
public function sendClientRecheck(Identification $event)
{
$client = $event->getClient();
$systemUser = $this->bankUserRepository->findByUsername(BankUser::SYSTEM_USER);
$requestingUserId = $systemUser ? $systemUser->getId() : null;
$this->kafkaNotifier->sendClientRecheck($client->getId(), $requestingUserId);
}
public static function getSubscribedEvents()
{
return [
Identification::IDENTIFICATION_EVENT => [['processClientSystemState'], ['sendSMS'], ['sendClientRecheck']],
];
}
}