<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Notifier;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Enum\PushChannel;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Enum\PushLevel;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Enum\PushTarget;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Enum\PushTransport;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Enum\PushType;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Notification\Notifier\NotifierInterface as CoreNotifierInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;

final readonly class FlashBagNotifier implements CoreNotifierInterface
{
    public function __construct(
        private RequestStack $requestStack,
    ) {
    }

    public function push(string $message, PushChannel $channel, PushTarget $target, PushLevel $level, PushTransport $transport, PushType $type, ?string $template = null): void
    {
        $session = $this->requestStack->getSession();
        /** @var FlashBagInterface $flashBag */
        $flashBag = $session->getBag('flashes');
        $flashBag->add($level->value, $message);
    }

    public static function supports(): PushTransport
    {
        return PushTransport::FLASH;
    }
}
