<?php

namespace App\Core\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Config;

class AffiliateRequestMail extends Mailable
{

    use Queueable, SerializesModels;

    public $tries = 5;
    public $timeout = 30;

    protected $param;


    public function __construct($param)
    {
        $this->param = $param;
    }

    public function build ()
    {
        try
        {
            $params = $this->param;
            $mailParams = $params['mailViewParams'] ;
            $mailData = $params['mailData'] ;
            $mailSenderAddress = Config::get('app.mailSenderAddress') ;
            $mailTitle = $mailData['to']["name"]. ' |  Affiliate Request Mail';

            app('translator')->setLocale(fillOnUndefined($params['mailViewParams'],'language', 'en'));


            /*echo view('emails.affiliateRequestMail', compact('mailParams', 'mailTitle'));
            die();*/

            return $this->from($mailSenderAddress,  'Extranetwork')
                ->view('emails.affiliateRequestMail', compact('mailParams', 'mailTitle'))
                ->to($mailData['to']["email"], $mailData['to']["name"])
                ->bcc($mailData['bcc'])
                ->subject($mailTitle)
                ->with(['message' => $this]);

        }
        catch ( Exception $e )
        {
            $message = $e->getFile()." ".$e->getLine()." ".$e->getMessage();
            Log::error($message);
            return output( ['status' => -1, 'message' => $e->getMessage()] );
        }
    }

}
