<?php

namespace Myvetshop\Module\Clinique\Notification;

use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;
use Myvetshop\Module\Clinique\Adapter\Messaging\MessagingFactory;
use Myvetshop\Module\Clinique\Entity\CustomerPush;

class PushNotificationSender
{
    private MessagingFactory $messagingFactory;

    public function __construct(
        MessagingFactory $messagingFactory
    ) {
        $this->messagingFactory = $messagingFactory;
    }

    /**
     * Envoi d'une notification à un utilisateur.
     */
    public function sendNotification(CustomerPush $customerPush, string $title, string $message): void
    {
        $messaging = $this->messagingFactory->createMessaging();

        $message = CloudMessage::withTarget('token', $customerPush->pushId)
            ->withNotification(Notification::create($title, $message));

        $messaging->send($message);
    }
}
