using System.Net;
using System.Net.Mail;

namespace e_suite.Service.Mail.Facade;

public class SmtpClientFacade : ISmtpClient
{
    private SmtpClient? _client;

    public SmtpClientFacade()
    {
        _client = new SmtpClient();
    }

    public SmtpClientFacade(string? host, int port)
    {
        _client = new SmtpClient(host, port);
    }

    public void Dispose()
    {
        if (_client == null)
            return;

        GC.SuppressFinalize(this);
        _client.Dispose();
        _client = null!;
    }

    public ICredentialsByHost? Credentials
    {
        get => _client!.Credentials;
        set => _client!.Credentials = value;
    }

    public bool EnableSsl
    {
        get => _client!.EnableSsl;
        set => _client!.EnableSsl = value;
    }

    public int Timeout
    {
        get => _client!.Timeout;
        set => _client!.Timeout = value;
    }

    public async Task SendMailAsync(MailMessage message, CancellationToken cancellationToken)
    {
        await _client!.SendMailAsync(message, cancellationToken);
    }
}