using ZB.MOM.WW.Configuration;

namespace ZB.MOM.WW.ScadaBridge.AuditLog.Site.Telemetry;

/// <summary>
/// Validates <see cref="SiteAuditTelemetryOptions"/> at host startup
/// (arch-review 08 round 2 NF4). <c>SiteAuditTelemetryActor</c> uses the two
/// interval knobs as raw scheduling delays (busy after a productive/faulted
/// drain, idle after an empty one), so a zero interval spins the drain loop and
/// a zero batch drains nothing. Idle must be &gt;= busy: a shorter idle interval
/// inverts the actor's back-off-when-empty intent.
/// </summary>
public sealed class SiteAuditTelemetryOptionsValidator : OptionsValidatorBase<SiteAuditTelemetryOptions>
{
    /// <inheritdoc />
    protected override void Validate(ValidationBuilder builder, SiteAuditTelemetryOptions options)
    {
        builder.RequireThat(options.BatchSize > 0,
            $"AuditLog:SiteTelemetry:{nameof(SiteAuditTelemetryOptions.BatchSize)} " +
            $"({options.BatchSize}) must be > 0.");

        builder.RequireThat(options.BusyIntervalSeconds > 0,
            $"AuditLog:SiteTelemetry:{nameof(SiteAuditTelemetryOptions.BusyIntervalSeconds)} " +
            $"({options.BusyIntervalSeconds}) must be > 0.");

        builder.RequireThat(options.IdleIntervalSeconds > 0,
            $"AuditLog:SiteTelemetry:{nameof(SiteAuditTelemetryOptions.IdleIntervalSeconds)} " +
            $"({options.IdleIntervalSeconds}) must be > 0.");

        builder.RequireThat(options.IdleIntervalSeconds >= options.BusyIntervalSeconds,
            $"AuditLog:SiteTelemetry:{nameof(SiteAuditTelemetryOptions.IdleIntervalSeconds)} " +
            $"({options.IdleIntervalSeconds}) must be >= " +
            $"{nameof(SiteAuditTelemetryOptions.BusyIntervalSeconds)} ({options.BusyIntervalSeconds}) " +
            "— the idle drain must back off at least as far as the busy drain.");
    }
}
