<?php

namespace App\Notifications;

use App\Models\Notification as NotificationModel;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;

class PushNotification extends Notification
{
    public function __construct(
        protected NotificationModel $notification
    ) {}

    public function via($notifiable): array
    {
        return [WebPushChannel::class];
    }

    public function toWebPush($notifiable, $notification): WebPushMessage
    {
        return (new WebPushMessage)
            ->title($this->notification->title)
            ->body($this->notification->body)
            ->icon( '/img/app_icons/icon-192.png')
            ->data([
                'url' => $this->notification->url,
                'notification_id' => $this->notification->id,
            ]);
    }
}
