<?php

namespace App\Jobs;

use App\Models;
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 SendNewUssdClientEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $ussd_client;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Models\Client $client)
    {
        $this->ussd_client = $client;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle(Mailer $mailer)
    {
        $client = $this->ussd_client;
        $emails = ['jim@click-mobile.com', 'priscilla@click-mobile.com','samuel@click-mobile.com'];
        $name = ucwords($client->name);
        $status = $client->status;
        $data = [
            'email' => strtolower($client->email),
            'name' => $name,
            'status' => $status
        ];
        $mailer->send('emails.new_ussd_client', $data, function ($message) use ($data, $emails) {
            $message->from('alerts@click-mobile.com', 'Click Mobile ERP');
            $message->to($emails)->subject('New USSD Client Details');
        });

        /*
        $emails = ['myoneemail@esomething.com', 'myother@esomething.com','myother2@esomething.com'];

        Mail::send('emails.welcome', [], function($message) use ($emails)
        {    
            $message->to($emails)->subject('This is test e-mail');    
        });
        */

    }
}
