<?php
namespace EasyChat\Library\Email;





final class LocalRelayMailTransport implements OutboundMailTransportInterface {
    public function code(): string { return 'local_relay'; }
    private function relayConfig(array $config): array {
        return array_merge($config, array(
            'smtp_host'=>'127.0.0.1',
            'smtp_port'=>25,
            'smtp_auth'=>false,
            'allow_private_server'=>true,
        ));
    }
    public function probe(array $config): array {
        try {
            (new SmtpTransport())->test($this->relayConfig($config));
            return array('success'=>true,'status'=>'ready','code'=>'local_relay_ready','transport'=>$this->code());
        } catch (\Throwable $e) {
            return array('success'=>false,'status'=>'unavailable','code'=>'local_relay_unavailable','transport'=>$this->code());
        }
    }
    public function send(array $config, MailEnvelope $mail): array {
        $result = (new SmtpTransport())->sendEnvelope($this->relayConfig($config), $mail);
        $result['transport'] = $this->code();
        return $result;
    }
}
