using ZB.MOM.WW.Configuration;

namespace ZB.MOM.WW.ScadaBridge.AuditLog.Central;

/// <summary>
/// Validates <see cref="AuditLogPurgeOptions"/> at host startup (arch-review 08
/// round 2 NF4). The class self-clamps at resolve time, but a plainly-wrong
/// config (zero cadence, zero batch, zero maintenance-command timeout) should
/// still fail the boot so the operator learns immediately.
/// <see cref="AuditLogPurgeOptions.IntervalOverride"/> is test-only (per the
/// class remarks) and is deliberately not validated.
/// </summary>
public sealed class AuditLogPurgeOptionsValidator : OptionsValidatorBase<AuditLogPurgeOptions>
{
    /// <inheritdoc />
    protected override void Validate(ValidationBuilder builder, AuditLogPurgeOptions options)
    {
        builder.RequireThat(options.IntervalHours > 0,
            $"AuditLog:Purge:{nameof(AuditLogPurgeOptions.IntervalHours)} " +
            $"({options.IntervalHours}) must be > 0.");

        // Backing field for the documented "ChannelPurgeBatchSize" config key.
        builder.RequireThat(options.ChannelPurgeBatchSizeConfigured > 0,
            $"AuditLog:Purge:{nameof(AuditLogPurgeOptions.ChannelPurgeBatchSizeConfigured)} " +
            $"(config key ChannelPurgeBatchSize = {options.ChannelPurgeBatchSizeConfigured}) must be > 0.");

        builder.RequireThat(options.MaintenanceCommandTimeoutMinutes > 0,
            $"AuditLog:Purge:{nameof(AuditLogPurgeOptions.MaintenanceCommandTimeoutMinutes)} " +
            $"({options.MaintenanceCommandTimeoutMinutes}) must be > 0.");
    }
}
