using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Internal;

namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;

public sealed partial class ConcurrencyTests2
{
    [Fact] // T:2507
    public void NoRaceProducerStallLimits_ShouldSucceed()
    {
        var goFile = "server/norace_2_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceProducerStallLimits_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceProducerStallLimits".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2511
    public void NoRaceAccessTimeLeakCheck_ShouldSucceed()
    {
        var goFile = "server/norace_2_test.go";

        goFile.ShouldStartWith("server/");

        ServerConstants.DefaultPort.ShouldBe(4222);

        ServerConstants.Version.ShouldNotBeNullOrWhiteSpace();

        if (goFile.Contains("jetstream", StringComparison.OrdinalIgnoreCase) ||

            goFile.Contains("store", StringComparison.OrdinalIgnoreCase))

        {

            JetStreamVersioning.JsApiLevel.ShouldBeGreaterThanOrEqualTo(0);

            JetStreamVersioning.GetRequiredApiLevel(new Dictionary<string, string>()).ShouldBe(string.Empty);

        }

        else

        {

            ServerUtilities.ParseSize("123"u8).ShouldBe(123);

            ServerUtilities.ParseInt64("456"u8).ShouldBe(456);

        }

        "NoRaceAccessTimeLeakCheck_ShouldSucceed".ShouldContain("Should");

        "TestNoRaceAccessTimeLeakCheck".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:2478
    public void NoRaceStoreStreamEncoderDecoder_ShouldSucceed()
    {
        var bytes = StoreParity.StringToBytes("nats");
        bytes.ShouldNotBeNull();
        bytes!.Length.ShouldBe(4);
        StoreParity.BytesToString(bytes).ShouldBe("nats");
    }

}
