<?php

namespace App\Jobs;

use App\Models\Subscription;
use App\Notifications\SubscriberNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Notification;

class SubscriberNotificationJob implements ShouldQueue
{
    use Queueable;

    /**
     * Create a new job instance.
     */
    public function __construct(
        public string $subject,
        public string $message_body
    ) {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        Subscription::chunk(100, function ($subscriptions) {
            Notification::send($subscriptions, new SubscriberNotification($this->subject, $this->message_body));
        });
    }
}
