using NATS.Server.Subscriptions;

namespace NATS.Server.Core.Tests.Subscriptions;

public class SubListCtorAndNotificationParityTests
{
    [Fact]
    public void Constructor_with_enableCache_false_disables_cache()
    {
        var subList = new SubList(enableCache: false);

        subList.CacheEnabled().ShouldBeFalse();
    }

    [Fact]
    public void NewSublistNoCache_factory_disables_cache()
    {
        var subList = SubList.NewSublistNoCache();

        subList.CacheEnabled().ShouldBeFalse();
    }

    [Fact]
    public void RegisterNotification_emits_true_on_first_interest_and_false_on_last_interest()
    {
        var subList = new SubList();
        var notifications = new List<bool>();
        subList.RegisterNotification(v => notifications.Add(v));

        var sub = new Subscription { Subject = "foo", Sid = "1" };
        subList.Insert(sub);
        subList.Remove(sub);

        notifications.ShouldBe([true, false]);
    }

    [Fact]
    public void SubjectMatch_alias_helpers_match_existing_behavior()
    {
        SubjectMatch.SubjectHasWildcard("foo.*").ShouldBeTrue();
        SubjectMatch.SubjectHasWildcard("foo.bar").ShouldBeFalse();

        SubjectMatch.IsValidLiteralSubject("foo.bar").ShouldBeTrue();
        SubjectMatch.IsValidLiteralSubject("foo.*").ShouldBeFalse();
    }
}
