<?php

namespace App\User\Framework\EventListener;

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Event\AuthenticationSuccessEvent;

final class LoginSuccessListener
{
    public function __construct(
        private readonly RequestStack $requestStack,
    ) {}

    #[AsEventListener(event: 'security.authentication.success')]
    public function setMercureTopics(AuthenticationSuccessEvent $event): void
    {
        // Set the unique Mercure topic name for the User's alerts
        $this->requestStack->getSession()->set('mercure_alert_topic', 'alerts_' . uniqid());
    }
}
