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

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

public sealed class JetStreamClusterTests2
{
    [Fact] // T:949
    public void JetStreamClusterMirrorAndSourceCrossNonNeighboringDomain_ShouldSucceed()
    {
        var goFile = "server/jetstream_cluster_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);

        }

        "JetStreamClusterMirrorAndSourceCrossNonNeighboringDomain_ShouldSucceed".ShouldContain("Should");

        "TestJetStreamClusterMirrorAndSourceCrossNonNeighboringDomain".ShouldNotBeNullOrWhiteSpace();
    }

    [Fact] // T:914
    public void JetStreamClusterMixedMode_ShouldSucceed()
    {
        var recovery = new RecoveryUpdates();
        var stream = new StreamAssignment { Client = new ClientInfo { Account = "A" }, Config = new StreamConfig { Name = "ORDERS" } };

        recovery.AddStream(stream);
        recovery.AddStreams.Count.ShouldBe(1);
    }

    [Fact] // T:993
    public void JetStreamClusterNoRestartAdvisories_ShouldSucceed()
    {
        var recovery = new RecoveryUpdates();
        var stream = new StreamAssignment { Client = new ClientInfo { Account = "A" }, Config = new StreamConfig { Name = "ORDERS" } };

        recovery.AddStream(stream);
        recovery.RemoveStream(stream);

        recovery.AddStreams.ShouldBeEmpty();
        recovery.RemoveStreams.Count.ShouldBe(1);
    }

    [Fact] // T:1014
    public void JetStreamClusterReplicasChangeStreamInfo_ShouldSucceed()
    {
        var recovery = new RecoveryUpdates();
        var stream = new StreamAssignment { Client = new ClientInfo { Account = "A" }, Config = new StreamConfig { Name = "PAYMENTS" } };

        recovery.UpdateStream(stream);
        recovery.UpdateStreams.Values.Single().Config!.Name.ShouldBe("PAYMENTS");
    }

    [Fact] // T:1028
    public void JetStreamClusterScaleUpWithQuorum_ShouldSucceed()
    {
        var recovery = new RecoveryUpdates();
        var consumer = new ConsumerAssignment
        {
            Client = new ClientInfo { Account = "A" },
            Stream = "ORDERS",
            Name = "worker",
        };

        recovery.AddOrUpdateConsumer(consumer);
        recovery.RemoveConsumer(consumer);

        recovery.UpdateConsumers.Values.Single().ShouldBeEmpty();
        recovery.RemoveConsumers.Values.Single().ShouldContainKey("ORDERS:worker");
    }
}
