<?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;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Mercure\Transport\MercureCustomOptions;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Notification\ChatNotificationInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\RecipientInterface;

class MercureNotification extends Notification implements ChatNotificationInterface
{
    /**
     * @param list<string> $topic
     */
    public function __construct(
        private readonly array $topic = [],
    ) {
        parent::__construct();
    }

    public function getChannels(RecipientInterface $recipient): array
    {
        return ['chat/mercure'];
    }

    public function asChatMessage(?RecipientInterface $recipient = null, ?string $transport = null): ChatMessage
    {
        $options = new MercureCustomOptions($this->topic, true);

        return ChatMessage::fromNotification($this)->options($options)->subject($this->getContent());
    }
}
