using ZB.MOM.WW.Configuration;

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

/// <summary>
/// Validates <see cref="SiteAuditRetentionOptions"/> at host startup
/// (arch-review 08 round 2 NF4). The option class self-clamps at resolve time,
/// but a plainly-wrong config (zero retention window, zero/negative purge
/// period, negative initial delay) should still fail the boot so the operator
/// learns immediately rather than trusting a silent clamp.
/// <see cref="SiteAuditRetentionOptions.PurgeIntervalOverride"/> is test-only
/// (per the class remarks) and is deliberately not validated.
/// </summary>
public sealed class SiteAuditRetentionOptionsValidator : OptionsValidatorBase<SiteAuditRetentionOptions>
{
    /// <inheritdoc />
    protected override void Validate(ValidationBuilder builder, SiteAuditRetentionOptions options)
    {
        builder.RequireThat(options.RetentionDays > 0,
            $"AuditLog:SiteRetention:{nameof(SiteAuditRetentionOptions.RetentionDays)} " +
            $"({options.RetentionDays}) must be > 0.");

        builder.RequireThat(options.PurgeInterval > TimeSpan.Zero,
            $"AuditLog:SiteRetention:{nameof(SiteAuditRetentionOptions.PurgeInterval)} " +
            $"({options.PurgeInterval}) must be > 0.");

        builder.RequireThat(options.InitialDelay >= TimeSpan.Zero,
            $"AuditLog:SiteRetention:{nameof(SiteAuditRetentionOptions.InitialDelay)} " +
            $"({options.InitialDelay}) must be >= 0.");
    }
}
