<?php

namespace App\Jobs;

use App\Notifications\PushNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class SendPushNotifications implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $users;
    public $message;
    public $description;
    public $image;

    /**
     * Create a new job instance.
     */
    public function __construct($users, $message, $description, $image)
    {
        $this->users = $users;
        $this->message = $message;
        $this->description = $description;
        $this->image = $image;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        Log::info("i am in send push notifications");
        foreach ($this->users as $user) {
            // Send the push notification to each selected user
            $user->notify(new PushNotification(
                $user,
                $this->message,
                $this->description,
                $this->image
            ));
        }
    }
}
