<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;


class SendEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $from;
    protected $emails;
    protected $subject;
    protected $data;
    protected $classImpl;
    protected $model;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($from,$emails,$subject,$data,$classImpl,$model = NULL)
    {
        $this->model = $model;
        $this->from = $from;
        $this->emails = $emails;
        $this->subject = $subject;
        $this->data = $data;
        $this->classImpl = $classImpl;
    }


    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if(isset($this->model))
            Mail::to($this->emails)->send(new $this->classImpl($this->from,$this->subject,$this->data,$this->model));
        else
           Mail::to($this->emails)->send(new $this->classImpl($this->from,$this->subject,$this->data));
        return Mail::failures();
    }


}
