<?php
namespace EasyChat\Library\Email;

final class DirectSmtpMailTransport implements OutboundMailTransportInterface {
    public function code(): string { return 'direct_smtp'; }
    public function probe(array $config): array {
        try {
            (new SmtpTransport())->test($config);
            return array('success'=>true,'status'=>'ready','code'=>'smtp_ready','transport'=>$this->code());
        } catch (\Throwable $e) {
            $code = preg_replace('/[^a-z0-9_\-]/i', '', $e->getMessage());
            return array('success'=>false,'status'=>'error','code'=>$code ?: 'smtp_failed','transport'=>$this->code());
        }
    }
    public function send(array $config, MailEnvelope $mail): array {
        return (new SmtpTransport())->sendEnvelope($config, $mail);
    }
}
