using FluentAssertions;

public class TrendCalculatorTests
{
    private static readonly DateTimeOffset BaseTime =
        new(2026, 6, 18, 12, 0, 0, TimeSpan.Zero);

    [Fact]
    public void ComputeRatePerMinute_TwoEntries_ReturnsCorrectRate()
    {
        var entries = new List<TrendHistoryEntry>
        {
            new(72m, BaseTime),
            new(95m, BaseTime.AddMinutes(10))
        };

        var rate = TrendCalculator.ComputeRatePerMinute(entries, windowMinutes: 30);

        rate.Should().Be(2.3m);
    }

    [Fact]
    public void ComputeRatePerMinute_SingleEntry_ReturnsNull()
    {
        var entries = new List<TrendHistoryEntry> { new(72m, BaseTime) };

        TrendCalculator.ComputeRatePerMinute(entries, windowMinutes: 30)
            .Should().BeNull();
    }

    [Fact]
    public void ExceedsThreshold_HeartRateRise_ReturnsTrue()
    {
        TrendCalculator.ExceedsThreshold("HEART_RATE", 0.6m, 0.5m).Should().BeTrue();
    }

    [Fact]
    public void ExceedsThreshold_Spo2Decline_ReturnsTrue()
    {
        TrendCalculator.ExceedsThreshold("SPO2", -0.3m, 0.2m).Should().BeTrue();
    }

    [Fact]
    public void ExceedsThreshold_StableRate_ReturnsFalse()
    {
        TrendCalculator.ExceedsThreshold("HEART_RATE", 0.3m, 0.5m).Should().BeFalse();
    }

    [Fact]
    public void DescribeTrend_FormatsCorrectly()
    {
        TrendCalculator.DescribeTrend("HEART_RATE", 0.77m, 95m)
            .Should().Be("Rapid rise: HEART_RATE rising at 0.77/min (current 95)");

        TrendCalculator.DescribeTrend("SPO2", -0.25m, 92m)
            .Should().Be("Rapid decline: SPO2 falling at 0.25/min (current 92)");
    }
}
