using ZB.MOM.WW.Configuration;

namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tracking;

/// <summary>
/// Validates <see cref="OperationTrackingOptions"/> at host startup (arch-review
/// 08 round 2 NF4). <see cref="OperationTrackingStore"/> opens the SQLite
/// connection string in its constructor, so an empty/blank connection string
/// must fail the host at boot rather than throw opaquely on first resolve. The
/// retention window must be positive — a zero would make the host's terminal-row
/// purge delete every tracking row.
/// </summary>
public sealed class OperationTrackingOptionsValidator : OptionsValidatorBase<OperationTrackingOptions>
{
    /// <inheritdoc />
    protected override void Validate(ValidationBuilder builder, OperationTrackingOptions options)
    {
        builder.RequireThat(!string.IsNullOrWhiteSpace(options.ConnectionString),
            $"ScadaBridge:OperationTracking:{nameof(OperationTrackingOptions.ConnectionString)} " +
            "must be a non-empty SQLite connection string.");

        builder.RequireThat(options.RetentionDays > 0,
            $"ScadaBridge:OperationTracking:{nameof(OperationTrackingOptions.RetentionDays)} " +
            $"({options.RetentionDays}) must be > 0.");
    }
}
