namespace ZB.MOM.WW.ScadaBridge.NotificationService;

/// <summary>
/// Abstraction over SMTP client for testability.
/// </summary>
public interface ISmtpClientWrapper
{
    /// <summary>
    /// Connects to the SMTP server.
    /// </summary>
    /// <param name="tlsMode">
    /// Explicit three-state TLS mode (None/StartTls/Ssl) — replaces the old
    /// <c>bool useTls</c> which could not represent implicit-SSL and silently fell
    /// back to opportunistic negotiation for non-StartTLS configurations.
    /// </param>
    /// <param name="connectionTimeoutSeconds">
    /// SMTP connection/operation timeout in seconds. A non-positive value
    /// leaves the client's default timeout in place.
    /// </param>
    /// <param name="host">SMTP server hostname or IP address.</param>
    /// <param name="port">SMTP server port.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task ConnectAsync(
        string host,
        int port,
        SmtpTlsMode tlsMode,
        int connectionTimeoutSeconds,
        CancellationToken cancellationToken = default);
    /// <summary>Authenticates to the SMTP server using the specified auth type and credentials.</summary>
    /// <param name="authType">Authentication mechanism (e.g. <c>PLAIN</c>, <c>XOAUTH2</c>).</param>
    /// <param name="credentials">Credential string appropriate for the auth type, or null.</param>
    /// <param name="oauth2UserName">
    /// Mailbox identity the OAuth2 access token was issued for (typically
    /// the SMTP <c>FromAddress</c>). Used as the <c>user=</c> field of the XOAUTH2
    /// SASL initial response — Microsoft 365 rejects an empty/mismatched user with
    /// <c>535 5.7.3</c>. Ignored for non-OAuth2 auth types; default <c>null</c> for
    /// callers that do not authenticate with OAuth2.
    /// </param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task AuthenticateAsync(
        string authType,
        string? credentials,
        string? oauth2UserName = null,
        CancellationToken cancellationToken = default);
    /// <summary>Sends an email message with the specified recipients via BCC.</summary>
    /// <param name="from">Sender address.</param>
    /// <param name="bccRecipients">Recipients delivered as BCC.</param>
    /// <param name="subject">Email subject line.</param>
    /// <param name="body">Plain-text email body.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task SendAsync(string from, IEnumerable<string> bccRecipients, string subject, string body, CancellationToken cancellationToken = default);
    /// <summary>Disconnects from the SMTP server gracefully.</summary>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    Task DisconnectAsync(CancellationToken cancellationToken = default);
}
