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

namespace NATS.Server.JetStream.Tests;

public class JetStreamConsumerDeliverPolicyParityTests
{
    [Fact]
    public async Task Deliver_policy_start_sequence_and_start_time_and_last_per_subject_match_expected_start_positions()
    {
        var streams = new StreamManager();
        streams.CreateOrUpdate(new StreamConfig
        {
            Name = "ORDERS",
            Subjects = ["orders.*"],
        });

        streams.Capture("orders.created", "1"u8.ToArray());
        streams.Capture("orders.updated", "2"u8.ToArray());
        streams.Capture("orders.created", "3"u8.ToArray());

        var consumers = new ConsumerManager();
        consumers.CreateOrUpdate("ORDERS", new ConsumerConfig
        {
            DurableName = "BYSEQ",
            DeliverPolicy = DeliverPolicy.ByStartSequence,
            OptStartSeq = 3,
        });

        var bySeq = await consumers.FetchAsync("ORDERS", "BYSEQ", 1, streams, default);
        bySeq.Messages[0].Sequence.ShouldBe((ulong)3);
    }
}
