using ZB.MOM.WW.Configuration;

namespace ZB.MOM.WW.ScadaBridge.ManagementService;

/// <summary>
/// Validates <see cref="ManagementServiceOptions"/> at startup. Both
/// <see cref="ManagementServiceOptions.CommandTimeout"/> and
/// <see cref="ManagementServiceOptions.LongRunningCommandTimeout"/> are used as Ask timeouts against
/// the ManagementActor; a zero/negative value makes every management command fail immediately (or Ask
/// forever). Registered with <c>ValidateOnStart()</c> so a bad <c>ScadaBridge:ManagementService</c>
/// section fails fast at boot with a clear, key-naming message.
/// <para>
/// <see cref="ManagementServiceOptions.SecuredWritePendingTtl"/> is intentionally NOT required positive:
/// a non-positive value legitimately disables server-side secured-write expiry.
/// </para>
/// </summary>
public sealed class ManagementServiceOptionsValidator : OptionsValidatorBase<ManagementServiceOptions>
{
    /// <inheritdoc />
    protected override void Validate(ValidationBuilder builder, ManagementServiceOptions options)
    {
        builder.RequireThat(options.CommandTimeout > TimeSpan.Zero,
            $"ScadaBridge:ManagementService:CommandTimeout must be a positive duration " +
            $"(was {options.CommandTimeout}); it is the Ask timeout for management commands.");

        builder.RequireThat(options.LongRunningCommandTimeout > TimeSpan.Zero,
            $"ScadaBridge:ManagementService:LongRunningCommandTimeout must be a positive duration " +
            $"(was {options.LongRunningCommandTimeout}); it is the Ask timeout for transport/deploy commands.");
    }
}
