<?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 LogMail extends Mailable
{

    use Queueable, SerializesModels;

    public $tries = 2;
    public $timeout = 20;

    protected $param;


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

    public function build()
    {
        try {
            $params = $this->param;
            $logMailAddress = Config::get('app.logMailAddress');
            $mailSenderAddress = Config::get('app.mailSenderAddress');

            $params['title'] = 'ENW LOG - ' . $params['title'];

            app('translator')->setLocale('tr');

            return $this->from($mailSenderAddress, 'Development Team')
                ->view('emails.logMail', compact('params'))
                ->to($logMailAddress, 'Development Team')
                //->bcc(['bd@extranetwork.com'])
                ->subject($params['title']);

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

}
