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

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

public partial class StorageEngineTests
{
    [Fact] // T:2952
    public void StoreStreamInteriorDeleteAccounting_ShouldSucceed()
    {
        var fs = NewMemStore(new StreamConfig
        {
            Name = "ACC",
            Subjects = ["acc"],
        });

        for (var i = 0; i < 10; i++)
            fs.StoreMsg("acc", null, null, 0);

        var (removed, err) = fs.RemoveMsg(5);
        removed.ShouldBeTrue();
        err.ShouldBeNull();

        var state = fs.State();
        state.Msgs.ShouldBe(9UL);
        state.FirstSeq.ShouldBe(1UL);
        state.LastSeq.ShouldBe(10UL);
        state.NumDeleted.ShouldBe(1);

        var (next, seq) = fs.LoadNextMsg("acc", false, 5, new StoreMsg());
        next.ShouldNotBeNull();
        seq.ShouldBe(6UL);

        fs.Stop();
    }
}
