using NeonSprawl.Server.Game.AbilityInput;
using Xunit;

namespace NeonSprawl.Server.Tests.Game.AbilityInput;

public sealed class InMemoryPlayerAbilityCooldownStoreTests
{
    [Fact]
    public void TryGetCooldownEndUtc_ShouldReturnEnd_WhenNowBeforeCooldownEnd()
    {
        // Arrange
        var store = new InMemoryPlayerAbilityCooldownStore();
        var t0 = new DateTimeOffset(2026, 4, 30, 12, 0, 0, TimeSpan.Zero);
        store.StartCooldown("p1", 2, t0, TimeSpan.FromSeconds(3));

        // Act
        var has = store.TryGetCooldownEndUtc("p1", 2, t0 + TimeSpan.FromSeconds(1), out var endUtc);

        // Assert
        Assert.True(has);
        Assert.Equal(t0 + TimeSpan.FromSeconds(3), endUtc);
    }

    [Fact]
    public void TryGetCooldownEndUtc_ShouldPruneAndReturnFalse_WhenNowAtOrAfterEnd()
    {
        // Arrange
        var store = new InMemoryPlayerAbilityCooldownStore();
        var t0 = new DateTimeOffset(2026, 4, 30, 12, 0, 0, TimeSpan.Zero);
        store.StartCooldown("p1", 0, t0, TimeSpan.FromSeconds(3));
        var after = t0 + TimeSpan.FromSeconds(5);

        // Act
        var pruned = store.TryGetCooldownEndUtc("p1", 0, after, out _);
        var second = store.TryGetCooldownEndUtc("p1", 0, after, out _);

        // Assert
        Assert.False(pruned);
        Assert.False(second);
    }
}
