<?php

namespace App\Jobs;

use App\Mail\VerifyCodeMail;
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\Mail;

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

    protected $data;
    protected $view;

    /**
     * Create a new job instance.
     * @param $data
     * @param $view
     */
    public function __construct($data, $view)
    {
        $this->data = $data;
        $this->view = $view;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {

        if($this->data['message']) {
            sendSMS($this->data['phone'], $this->data['message']);
        }

        $data = new VerifyCodeMail($this->data, $this->view);
        Mail::to($this->data['email'])->send($data);
    }
}
