<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushMessage;
use NotificationChannels\WebPush\WebPushChannel;

class TamuBaruNotification extends Notification
{
    use Queueable;

    protected $tamu;

    /**
     * Create a new notification instance.
     */
    public function __construct($tamu)
    {
        $this->tamu = $tamu;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
{
    return [WebPushChannel::class];  // pakai class, bukan string
}

    /**
     * Get the WebPush representation of the notification.
     */
    public function toWebPush($notifiable, $notification)
{
    return (new WebPushMessage)
        ->title('Ada Tamu Baru!')
        ->body($this->tamu->nama_tamu . ' baru saja konfirmasi kehadiran.')
        ->action('Lihat', 'view_guest')
        ->data([
            'id'  => $this->tamu->id,
            'url' => route('izin_tamu.admin_izin.index') // 🔥 diarahkan ke index admin
        ])
        ->icon('/images/logo.png');
}


    /**
     * Get the array representation of the notification.
     */
    public function toArray(object $notifiable): array
    {
        return [
            'tamu_id' => $this->tamu->id,
            'nama_tamu' => $this->tamu->nama_tamu,
        ];
    }
}
