using Microsoft.Extensions.Options;
namespace ZB.MOM.WW.ScadaBridge.NotificationOutbox;
///
/// Configuration options for the SMS (Twilio-REST) notification delivery adapter,
/// bound from the ScadaBridge:Sms configuration section.
///
/// SMS connection settings are primarily carried by the deployed
/// SmsConfiguration entity. These values supply the documented fallbacks /
/// caps used by the central Notification Outbox's
/// SmsNotificationDeliveryAdapter: caps the
/// composed body, and is the per-request
/// timeout used when the deployed SmsConfiguration.ConnectionTimeoutSeconds
/// field is left unset (non-positive) — a value present on the row always takes
/// precedence.
///
public sealed class SmsOptions
{
///
/// Maximum length of the composed SMS body; longer bodies are truncated with an
/// ellipsis before the Twilio POST. Default 1600 (Twilio's per-message maximum).
/// Must be strictly positive.
///
public int MaxMessageLength { get; set; } = 1600;
///
/// Per-request connection/response timeout (seconds) used when the deployed
/// SmsConfiguration.ConnectionTimeoutSeconds is unset (non-positive).
/// Default 30s. Must be strictly positive.
///
public int ConnectionTimeoutSeconds { get; set; } = 30;
}
///
/// Validates on startup. A non-positive
/// would truncate every body to nothing,
/// and a non-positive would make
/// the per-request timeout meaningless, so both are required to be strictly positive.
///
public sealed class SmsOptionsValidator : IValidateOptions
{
///
public ValidateOptionsResult Validate(string? name, SmsOptions options)
{
ArgumentNullException.ThrowIfNull(options);
var failures = new List();
if (options.MaxMessageLength <= 0)
{
failures.Add(
$"ScadaBridge:Sms:{nameof(SmsOptions.MaxMessageLength)} ({options.MaxMessageLength}) " +
"must be > 0; it caps the composed SMS body length.");
}
if (options.ConnectionTimeoutSeconds <= 0)
{
failures.Add(
$"ScadaBridge:Sms:{nameof(SmsOptions.ConnectionTimeoutSeconds)} ({options.ConnectionTimeoutSeconds}) " +
"must be > 0; it is the per-request Twilio timeout fallback.");
}
return failures.Count > 0
? ValidateOptionsResult.Fail(failures)
: ValidateOptionsResult.Success;
}
}