<?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 ManualPaymentMail 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') ;
            app('translator')->setLocale($mailParams["language_code"]);

            $description = __('api-manual_payment_mail-desc',[
                'title' => $mailParams['process_title'] ,
                'date' => $mailParams['date_time'],
                'amount' => $mailParams['amount'],
                'currency' => $mailParams['currency']
            ]);

            return $this->from($mailSenderAddress,  'Extranetwork - '.$mailParams['property_name'])
                ->view('emails.manualPaymentMail', compact('mailParams', 'description'))
                ->to($mailData['to']["email"])
                ->bcc($mailData['bcc'])
                ->subject(__('api-manual_payment_mail-subject'))
                ->with(['message' => $this]);


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

}
