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

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

/// <summary>
/// Eager startup validation for <see cref="OperationTrackingOptions"/>
/// (arch-review 08 round 2 NF4). The store opens the SQLite connection string at
/// construction, so an empty connection string must fail the host at boot; the
/// retention window must be positive or terminal-row purge would delete
/// everything.
/// </summary>
public class OperationTrackingOptionsValidatorTests
{
    [Fact]
    public void DefaultOptions_AreValid()
    {
        var validator = new OperationTrackingOptionsValidator();
        Assert.True(validator.Validate(null, new OperationTrackingOptions()).Succeeded);
    }

    [Fact]
    public void EmptyConnectionString_Fails()
    {
        var validator = new OperationTrackingOptionsValidator();
        var result = validator.Validate(null, new OperationTrackingOptions { ConnectionString = "" });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(OperationTrackingOptions.ConnectionString), StringComparison.Ordinal));
    }

    [Fact]
    public void ZeroRetentionDays_Fails()
    {
        var validator = new OperationTrackingOptionsValidator();
        var result = validator.Validate(null, new OperationTrackingOptions { RetentionDays = 0 });
        Assert.False(result.Succeeded);
        Assert.Contains(result.Failures!,
            f => f.Contains(nameof(OperationTrackingOptions.RetentionDays), StringComparison.Ordinal));
    }
}
