<?php
namespace FlexApp\Service;
use FlexApp\Repository\ConsultantRepository;
use Psr\Cache\InvalidArgumentException;
use WebBundle\Exception\PortalHelperException;
class AliasByConsLoginProvider
{
private ConsSchedule $consSchedule;
/** @required */
public ConsultantRepository $consultantRepository;
public function __construct(ConsSchedule $consSchedule)
{
$this->consSchedule = $consSchedule;
}
public function getAlias(string $consLogin) {
try {
$schedule = $this->consSchedule->getSchedule() ?? [];
$consultData = $schedule['result']['consultData'] ?? [];
foreach ($consultData as $val) {
$val['pseudonym'] ??= 'T.E. Specialist';
if ($consLogin === $val['login']) {
return $val['pseudonym'];
}
}
/** @var \FlexApp\Entity\ConsultantEntity $consEntity */
$consEntity = $this->consultantRepository->findOneBy(['portalLogin' => $consLogin]);
if (!$consEntity) {
return 'Support';
}
if (!$consEntity->getNameForChat()) {
return 'T.E. Support';
}
return $consEntity->getNameForChat();
} catch (InvalidArgumentException $e) {
return 'TE Manager';
} catch (PortalHelperException $e) {
return 'TE Specialist';
}
}
}