<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Mail\Mailer;


class SendOtpEmailAlert implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $otp_set;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($otp_set)
    {
        $this->otp_set = $otp_set;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Mailer $mailer)
    {
        $otp_set = $this->otp_set;
        $emails = [
            $otp_set['email']
        ];
        $data = [
            'otp' => $otp_set['otp'],
            'auth_name' => $otp_set['auth_name']
        ];
        $mailer->send('emails.otp', $data, function ($message) use ($data, $emails) {
            $message->from('alerts@click-mobile.com', 'Click Mobile ERP');
            $message->to($emails)->subject('Login OTP');
        });
    }
}
