<?php

namespace App\Http\Middleware;

use Closure;

class OverwriteMail
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $conf = [
            'driver' => 'smtp',
            'host' => 'mail.wingdigital.com.br',
            'port' => 587,
            'from' => [
                'address' => 'maurojunior@wingdigital.com.br',
                'name' => 'Mauro Antônio Correia Júnior',
            ],
            'encryption' => 'tls',
            'username' => 'maurojunior@wingdigital.com.br',
            'password' => 'zuno1258',
            'sendmail' => '/usr/sbin/sendmail -bs',
            'markdown' => [
                'theme' => 'default',
                'paths' => [
                    resource_path('views/vendor/mail'),
                ],
            ],
            'log_channel' => env('MAIL_LOG_CHANNEL')
        ];

        Config::set('mail', $conf);

        $app = App::getInstance();
        $app->register('Illuminate\Mail\MailServiceProvider');

        return $next($request);
    }
}
