<?php

namespace App\Jobs\Subscription;

use App\Models\Subscription;
use App\Notifications\Subscription\SubscriptionStatusNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

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

    public Subscription $subscription;
    public $type;

    public function __construct(Subscription $subscription, $type)
    {
        $this->subscription = $subscription;
        $this->type = $type;
    }

    public function handle()
    {
        if ($this->subscription->user) {
            $this->subscription->user->notify(new SubscriptionStatusNotification($this->subscription, $this->type));
        }
    }
}
