namespace ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;

public class SmtpConfiguration
{
    /// <summary>Gets or sets the primary key.</summary>
    public int Id { get; set; }
    /// <summary>Gets or sets the SMTP server hostname or IP address.</summary>
    public string Host { get; set; }
    /// <summary>Gets or sets the SMTP server port number.</summary>
    public int Port { get; set; }
    /// <summary>Gets or sets the authentication type (e.g. Basic, OAuth2ClientCredentials).</summary>
    public string AuthType { get; set; }
    /// <summary>Gets or sets the serialized credentials (password or OAuth2 client secret), or null when not applicable.</summary>
    public string? Credentials { get; set; }
    /// <summary>Gets or sets the TLS mode (None, StartTLS, or SSL), or null to use the provider default.</summary>
    public string? TlsMode { get; set; }

    /// <summary>
    /// Gets or sets the email delivery transport ("Smtp" or "Ews"). Null/empty means Smtp
    /// (legacy rows). Under Ews, <see cref="Host"/> holds the full EWS endpoint URL,
    /// <see cref="AuthType"/> must be Basic, and Port/TlsMode/OAuth2* are unused.
    /// </summary>
    public string? Transport { get; set; }

    /// <summary>Gets or sets the sender address placed in the From header.</summary>
    public string FromAddress { get; set; }
    /// <summary>Gets or sets the connection timeout in seconds.</summary>
    public int ConnectionTimeoutSeconds { get; set; }
    /// <summary>Gets or sets the maximum number of concurrent SMTP connections.</summary>
    public int MaxConcurrentConnections { get; set; }
    /// <summary>Gets or sets the maximum number of delivery retries before parking.</summary>
    public int MaxRetries { get; set; }
    /// <summary>Gets or sets the delay between retry attempts.</summary>
    public TimeSpan RetryDelay { get; set; }

    /// <summary>
    /// Gets or sets the OAuth2 token-endpoint authority template, or null to use the
    /// Microsoft 365 default (<c>https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token</c>).
    /// The stored value is the full token-endpoint URL with an optional <c>{tenant}</c>
    /// placeholder substituted from the credential's tenant id.
    /// </summary>
    public string? OAuth2Authority { get; set; }

    /// <summary>
    /// Gets or sets the OAuth2 scope requested from the token endpoint, or null to use the
    /// Microsoft 365 default (<c>https://outlook.office365.com/.default</c>).
    /// </summary>
    public string? OAuth2Scope { get; set; }

    /// <summary>
    /// Initializes a new <see cref="SmtpConfiguration"/> with required fields.
    /// </summary>
    /// <param name="host">SMTP server hostname or IP address.</param>
    /// <param name="authType">Authentication type string (e.g. Basic, OAuth2ClientCredentials).</param>
    /// <param name="fromAddress">Sender address for the From header.</param>
    public SmtpConfiguration(string host, string authType, string fromAddress)
    {
        Host = host ?? throw new ArgumentNullException(nameof(host));
        AuthType = authType ?? throw new ArgumentNullException(nameof(authType));
        FromAddress = fromAddress ?? throw new ArgumentNullException(nameof(fromAddress));
    }
}
