using NATS.Server.JetStream.Models;
using NATS.Server.JetStream;
using NATS.Server.JetStream.Publish;

namespace NATS.Server.Tests;

public class JetStreamStreamConfigBehaviorTests
{
    [Fact]
    public void Stream_honors_dedup_window_and_sealed_delete_purge_guards()
    {
        var streamManager = new StreamManager();
        streamManager.CreateOrUpdate(new StreamConfig
        {
            Name = "ORDERS",
            Subjects = ["orders.*"],
            DuplicateWindowMs = 10_000,
            Sealed = false,
            DenyDelete = false,
            DenyPurge = false,
        });

        var publisher = new JetStreamPublisher(streamManager);
        publisher.TryCaptureWithOptions("orders.created", "one"u8.ToArray(), new PublishOptions { MsgId = "m-1" }, out var first).ShouldBeTrue();
        publisher.TryCaptureWithOptions("orders.created", "two"u8.ToArray(), new PublishOptions { MsgId = "m-1" }, out var second).ShouldBeTrue();
        second.Seq.ShouldBe(first.Seq);

        streamManager.CreateOrUpdate(new StreamConfig
        {
            Name = "ORDERS",
            Subjects = ["orders.*"],
            DuplicateWindowMs = 10_000,
            Sealed = true,
            DenyDelete = true,
            DenyPurge = true,
        });

        streamManager.DeleteMessage("ORDERS", first.Seq).ShouldBeFalse();
        streamManager.Purge("ORDERS").ShouldBeFalse();
    }
}
