<?php
/**
 * Mail Transport
 */

namespace MNM\Spitzner\Overwrite\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Mail\MessageInterface;
use Laminas\Mail\Transport\SmtpOptions;
use Laminas\Mail\Transport\Smtp;

class Transport extends \Sendinblue\Sendinblue\Model\Transport
{
    /**
     * @param MessageInterface $message
     * @param null $parameters
     * @throws \InvalidArgumentException
     */
    public function __construct(MessageInterface $message, ScopeConfigInterface $scopeConfig ){
            $this->_message = $message;
            $this->_scopeConfig = $scopeConfig;
        $relaySib = $scopeConfig->getValue('sendinblue/relay_data_status', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
        if ($relaySib == 'enabled') {
            $smtpHost = "smtp-relay.brevo.com";
            $smtpAuthentication = $scopeConfig->getValue('sendinblue/smtp_authentication', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
            $smtpTls = $scopeConfig->getValue('sendinblue/smtp_tls', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
            $smtpPort = $scopeConfig->getValue('sendinblue/smtp_port', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
            $smtpUsername = $scopeConfig->getValue('sendinblue/smtp_username', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
            $smtpPassword = $scopeConfig->getValue('sendinblue/smtp_password', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
/**MNM updated "instanceof Message" to "instanceof MessageInterface" **/
            if ($message instanceof MessageInterface) {
		        $this->transport = new Smtp(new SmtpOptions([
			        'host' => $smtpHost,
			        'port' => $smtpPort,
			        'connection_class' => $smtpAuthentication,
			        'connection_config' => [
				        'username' => $smtpUsername,
				        'password' => $smtpPassword,
				        'ssl' => $smtpTls,
			        ],
		        ]));
	        }
        }
    }
}
