<?php declare(strict_types=1);
namespace App\StartPlatz\Bundle\GruendungsstipendiumBundle\EventSubscriber;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsApplicationApprovedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsApplicationDeletedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsApplicationFinalizedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsApplicationRejectedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsApplicationStatusResetEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsJuryAdmittedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsJuryRecommendedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsJuryRejectedEvent;
use App\StartPlatz\Bundle\GruendungsstipendiumBundle\Event\GsJurySessionStatusChangedEvent;
use App\StartPlatz\Ecosystem\Evidence\SystemEvidenceRecorder;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class GsEvidenceSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly SystemEvidenceRecorder $evidenceRecorder
) {}
public static function getSubscribedEvents(): array
{
return [
GsApplicationApprovedEvent::class => 'onApplicationApproved',
GsApplicationRejectedEvent::class => 'onApplicationRejected',
GsJuryAdmittedEvent::class => 'onJuryAdmitted',
GsJuryRecommendedEvent::class => 'onJuryRecommended',
GsJuryRejectedEvent::class => 'onJuryRejected',
GsApplicationFinalizedEvent::class => 'onApplicationFinalized',
GsApplicationDeletedEvent::class => 'onApplicationDeleted',
GsApplicationStatusResetEvent::class => 'onApplicationStatusReset',
GsJurySessionStatusChangedEvent::class => 'onJurySessionStatusChanged',
];
}
public function onApplicationApproved(GsApplicationApprovedEvent $event): void
{
$app = $event->application;
$this->evidenceRecorder->documentApplicationApproval(
$app->getId(),
$app->getBatchId(),
['startup_name' => $app->getStartupName()],
$event->documentedBy
);
}
public function onApplicationRejected(GsApplicationRejectedEvent $event): void
{
$app = $event->application;
$this->evidenceRecorder->documentApplicationRejection(
$app->getId(),
$app->getBatchId(),
array_filter([
'startup_name' => $app->getStartupName(),
'reason' => $event->reason,
]),
$event->documentedBy
);
}
public function onJuryAdmitted(GsJuryAdmittedEvent $event): void
{
$app = $event->application;
$session = $event->session;
$this->evidenceRecorder->documentJuryAdmission(
$app->getId(),
$session->getId(),
[
'startup_name' => $app->getStartupName(),
'session_name' => $session->getName(),
'jury_date' => $session->getJuryDate()?->format('Y-m-d'),
],
$event->documentedBy
);
}
public function onJuryRecommended(GsJuryRecommendedEvent $event): void
{
$app = $event->application;
$this->evidenceRecorder->documentJuryRecommendation(
$app->getId(),
$event->session->getId(),
[
'startup_name' => $app->getStartupName(),
'score' => $app->getRatingAverage(),
],
$event->documentedBy
);
}
public function onJuryRejected(GsJuryRejectedEvent $event): void
{
$app = $event->application;
$this->evidenceRecorder->documentJuryRejection(
$app->getId(),
$event->session->getId(),
[
'startup_name' => $app->getStartupName(),
'score' => $app->getRatingAverage(),
],
$event->documentedBy
);
}
public function onApplicationFinalized(GsApplicationFinalizedEvent $event): void
{
$app = $event->application;
$result = $event->result;
$this->evidenceRecorder->documentFinalization(
$app->getId(),
$app->getBatchId(),
[
'member_created' => $result->memberCreated,
'team_created' => $result->teamCreated,
'member_id' => $result->member->getId(),
'team_id' => $result->team->getId(),
],
$event->documentedBy
);
}
public function onApplicationDeleted(GsApplicationDeletedEvent $event): void
{
$this->evidenceRecorder->documentApplicationDeletion(
$event->applicationId,
$event->batchId,
[
'startup_name' => $event->startupName,
'email' => $event->email,
],
$event->documentedBy
);
}
public function onApplicationStatusReset(GsApplicationStatusResetEvent $event): void
{
$app = $event->application;
$this->evidenceRecorder->documentApplicationStatusReset(
$app->getId(),
$app->getBatchId(),
[
'old_status' => $event->oldStatus,
'new_status' => 'applied',
'startup_name' => $app->getStartupName(),
],
$event->documentedBy
);
}
public function onJurySessionStatusChanged(GsJurySessionStatusChangedEvent $event): void
{
$this->evidenceRecorder->documentJurySessionStatusChange(
$event->session->getId(),
[
'old_status' => $event->oldStatus,
'new_status' => $event->newStatus,
'session_name' => $event->session->getName(),
],
$event->documentedBy
);
}
}