<?php

declare(strict_types=1);

namespace App\Domain\Shared\Infrastructure\Service;

use App\Domain\Shared\Domain\Contract\NotificationInterface;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;

readonly class SymfonyNotification implements NotificationInterface
{
    public function __construct(
        private HubInterface $hub
    ) {
    }

    public function sendSuccess(string $message): void
    {
        $this->sendUpdate(['status' => 'success', 'message' => $message]);
    }

    public function sendError(string $message): void
    {
        $this->sendUpdate(['status' => 'error', 'message' => $message]);
    }

    public function sendInfo(string $message): void
    {
        $this->sendUpdate(['status' => 'info', 'message' => $message]);
    }

    public function sendWarning(string $message): void
    {
        $this->sendUpdate(['status' => 'warning', 'message' => $message]);
    }

    public function sendUpdate(array $data): void
    {
        $update = new Update(
            'notifications',
            json_encode($data)
        );

        $this->hub->publish($update);
    }
}
