<?php

    namespace App\Http\Services;

    use sngrl\PhpFirebaseCloudMessaging\Client;
    use sngrl\PhpFirebaseCloudMessaging\Message;
    use sngrl\PhpFirebaseCloudMessaging\Notification;
    use sngrl\PhpFirebaseCloudMessaging\Recipient\Device;

    class NotificatorApi
    {

        protected const FCM_API_KEY = 'AAAACwFRz2s:APA91bHBdBKHClRiDNTc-EwJzZeaxu5d2mFsmcnTGDi1owFZqMSQ0V4v3-Jl3kJauMi3bcxpte6KNMxtxeJTxLxcdasNAMUHzdJbg8jSzE_vwPrXO9yRB0nRt2xsWf85BhamuL9N2X_i';


        public function sendNotification(string $title, string $body, string $clientToken): void
        {
            $client = new Client();
            $client->setApiKey(self::FCM_API_KEY);
            $client->injectGuzzleHttpClient(new \GuzzleHttp\Client());

            $message = new Message();

            $message->setNotification(
                new Notification(
                    $title,
                    $body
                )
            );
            $message->addRecipient(new Device($clientToken));
            $client->send($message);
        }
    }