<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;
use Illuminate\Bus\Queueable;
use NotificationChannels\Fcm\Resources\Notification as fcmNotificationClass;


class FcmNotification extends Notification
{
    use Queueable;

    private string $title;
    private string $body;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(string $title, string $body)
    {
        $this->title = $title;
        $this->body  = $body;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable)
    {
        return FcmMessage::create()
            ->setData([])
            ->setNotification(
                fcmNotificationClass::create()
                    ->setTitle($this->title)
                    ->setBody($this->body)
            );
        //  ->setImage('http://example.com/url-to-image-here.png'))

    }

    // optional method when using kreait/laravel-firebase:^3.0, this method can be omitted, defaults to the default project
    /*  public function fcmProject($notifiable, $message)
    {
        // $message is what is returned by `toFcm`
        return 'app'; // name of the firebase project to use
    } */
}
