<?php

namespace App\Jobs;

use App\Mail\LoanStoreMail;
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\Auth;
use Illuminate\Support\Facades\Mail;

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

    private $user;
    private $loan;

    /**
     * Create a new job instance.
     */
    public function __construct($user, $loan)
    {
        $this->user = $user;
        $this->loan = $loan;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        // Send an email to inform that a loan was send to users having that permission
        Mail::to("aminebendriouch.dev@gmail.com")->send(new LoanStoreMail($this->user, $this->loan));
    }
}
