using System;
using StellaOps.Feedser.Source.Ghsa.Internal;
using Xunit;

namespace StellaOps.Feedser.Source.Ghsa.Tests.Ghsa;

public class GhsaDiagnosticsTests : IDisposable
{
    private readonly GhsaDiagnostics diagnostics = new();

    [Fact]
    public void RecordRateLimit_PersistsSnapshot()
    {
        var snapshot = new GhsaRateLimitSnapshot(
            Phase: "list",
            Resource: "core",
            Limit: 5000,
            Remaining: 100,
            Used: 4900,
            ResetAt: DateTimeOffset.UtcNow.AddMinutes(1),
            ResetAfter: TimeSpan.FromMinutes(1),
            RetryAfter: TimeSpan.FromSeconds(10));

        diagnostics.RecordRateLimit(snapshot);

        var stored = diagnostics.GetLastRateLimitSnapshot();
        Assert.NotNull(stored);
        Assert.Equal(snapshot, stored);
    }

    public void Dispose()
    {
        diagnostics.Dispose();
    }
}
