<?php

namespace App\Mailer;

use App\Models\Sender;
use Illuminate\Support\Facades\Config;
use Swift_SmtpTransport;
use Illuminate\Support\Facades\Mail;

class DynamicMailConfig
{
    public static function setConfig()
    {
        $email = DynamicMailConfig::getEmailSender();

        Config::set('mail.mailers.smtp.username', $email->address);
        Config::set('mail.mailers.smtp.password', $email->password);
    }

    public static function getEmailSender()
    {
        $email = Sender::query()->orderBy('count', 'asc')->first();

        $count = $email->count + 1;

        $email->update([
                    'count' => $count,
        ]);

        return $email;
    }
}
