using StellaOps.Feedser.Models;
using Xunit;

namespace StellaOps.Feedser.Models.Tests;

public sealed class EvrPrimitiveExtensionsTests
{
    [Fact]
    public void ToNormalizedVersionRule_ProducesRangeForIntroducedAndFixed()
    {
        var primitive = new EvrPrimitive(
            Introduced: new EvrComponent(1, "1.2.3", "4"),
            Fixed: new EvrComponent(1, "1.2.9", "0ubuntu1"),
            LastAffected: null);

        var rule = primitive.ToNormalizedVersionRule("ubuntu:focal");

        Assert.NotNull(rule);
        Assert.Equal(NormalizedVersionSchemes.Evr, rule!.Scheme);
        Assert.Equal(NormalizedVersionRuleTypes.Range, rule.Type);
        Assert.Equal("1:1.2.3-4", rule.Min);
        Assert.True(rule.MinInclusive);
        Assert.Equal("1:1.2.9-0ubuntu1", rule.Max);
        Assert.False(rule.MaxInclusive);
        Assert.Equal("ubuntu:focal", rule.Notes);
    }

    [Fact]
    public void ToNormalizedVersionRule_GreaterThanOrEqualWhenOnlyIntroduced()
    {
        var primitive = new EvrPrimitive(
            Introduced: new EvrComponent(0, "2.0.0", null),
            Fixed: null,
            LastAffected: null);

        var rule = primitive.ToNormalizedVersionRule();

        Assert.NotNull(rule);
        Assert.Equal(NormalizedVersionRuleTypes.GreaterThanOrEqual, rule!.Type);
        Assert.Equal("2.0.0", rule.Min);
        Assert.True(rule.MinInclusive);
    }
}
