<?php

namespace App\Jobs;

use App\Tools\SmsTools;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;

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

    protected $client;
    protected $total;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(User $client, $total)
    {
        $this->client = $client;
        $this->total = $total;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $user = $this->client;
        $totalRecipient = $this->total;
        try
        {
            $m_email = 'npontualph@gmail.com';
            if(!empty($m_email)) {
                //prepare data to pass to email view
                $data = [
                    'user' => $user,
                    'total' => $totalRecipient,
                ];
                //send email notification to client
                Mail::send('emails.blast_alert', $data, function ($m) use ($m_email) {
                    $m->from('npontualph@gmail.com', 'MESSENGER');
                    $m->replyTo('support@npontu.com', 'Npontu Support');
                    $m->to('support@npontu.com', 'Npontu Support Team');
                    $m->subject('SMS Blast Alert');
                });
            }
        }
        catch(\Throwable $ex){}

    }
}
