// Copyright 2025 The NATS Authors
// Licensed under the Apache License, Version 2.0

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

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

public sealed class MqttHandlerTests
{
    [Fact] // T:2272
    public void MQTTStreamReplicasConfigReload_ShouldSucceed()
    {
        var err = JsApiErrors.NewJSStreamReplicasNotSupportedError();
        err.Code.ShouldBe(JsApiErrors.StreamReplicasNotSupported.Code);
        err.ErrCode.ShouldBe(JsApiErrors.StreamReplicasNotSupported.ErrCode);
        err.Description.ShouldBe("replicas > 1 not supported in non-clustered mode");
    }

    [Fact]
    public void MQTTSubWithNATSStream_ShouldSucceed()
    {
        var account = new Account { Name = "A" };
        var stream = NatsStream.Create(
            account,
            new StreamConfig { Name = "MQTT", Subjects = ["mqtt.>"], Storage = StorageType.MemoryStorage },
            null,
            null,
            null,
            null);

        stream.ShouldNotBeNull();

        var (consumer, error) = stream!.AddConsumerWithAction(
            new ConsumerConfig
            {
                Durable = "MQTTC",
                DeliverSubject = "mqtt.deliver",
                AckPolicy = AckPolicy.AckExplicit,
            },
            oname: "MQTTC",
            action: ConsumerAction.Create,
            pedantic: false);

        error.ShouldBeNull();
        consumer.ShouldNotBeNull();
        consumer!.GetInfo().Stream.ShouldBe("MQTT");
    }
}
