using NATS.Server.LeafNodes;
using NATS.Server.Subscriptions;

namespace NATS.Server.LeafNodes.Tests.LeafNodes;

public class LeafSubKeyParityBatch2Tests
{
    [Fact]
    public void Constants_match_go_leaf_key_and_delay_values()
    {
        LeafSubKey.KeyRoutedSub.ShouldBe("R");
        LeafSubKey.KeyRoutedSubByte.ShouldBe((byte)'R');
        LeafSubKey.KeyRoutedLeafSub.ShouldBe("L");
        LeafSubKey.KeyRoutedLeafSubByte.ShouldBe((byte)'L');
        LeafSubKey.SharedSysAccDelay.ShouldBe(TimeSpan.FromMilliseconds(250));
        LeafSubKey.ConnectProcessTimeout.ShouldBe(TimeSpan.FromSeconds(2));
    }

    [Fact]
    public void KeyFromSub_matches_go_subject_and_queue_shape()
    {
        LeafSubKey.KeyFromSub(NewSub("foo")).ShouldBe("foo");
        LeafSubKey.KeyFromSub(NewSub("foo", "bar")).ShouldBe("foo bar");
    }

    [Fact]
    public void KeyFromSubWithOrigin_matches_go_routed_and_leaf_routed_shapes()
    {
        LeafSubKey.KeyFromSubWithOrigin(NewSub("foo")).ShouldBe("R foo");
        LeafSubKey.KeyFromSubWithOrigin(NewSub("foo", "bar")).ShouldBe("R foo bar");
        LeafSubKey.KeyFromSubWithOrigin(NewSub("foo"), "leaf").ShouldBe("L foo leaf");
        LeafSubKey.KeyFromSubWithOrigin(NewSub("foo", "bar"), "leaf").ShouldBe("L foo bar leaf");
    }

    private static Subscription NewSub(string subject, string? queue = null)
        => new()
        {
            Subject = subject,
            Queue = queue,
            Sid = Guid.NewGuid().ToString("N"),
        };
}
