using NATS.Server.JetStream.MirrorSource;
using NATS.Server.JetStream.Models;
using NATS.Server.JetStream.Storage;

namespace NATS.Server.JetStream.Tests.JetStream;

public class JetStreamMirrorSourceStrictRuntimeTests
{
    [Fact]
    public async Task Mirror_source_transform_and_cross_account_filters_follow_runtime_contract()
    {
        var sourceTarget = new MemStore();
        var source = new SourceCoordinator(sourceTarget, new StreamSourceConfig
        {
            Name = "SRC",
            SubjectTransformPrefix = "agg.",
            SourceAccount = "A",
        });

        await source.OnOriginAppendAsync(new StoredMessage
        {
            Sequence = 1,
            Subject = "orders.created",
            Payload = "ok"u8.ToArray(),
            Account = "A",
        }, default);
        await source.OnOriginAppendAsync(new StoredMessage
        {
            Sequence = 2,
            Subject = "orders.created",
            Payload = "skip"u8.ToArray(),
            Account = "B",
        }, default);

        var state = await sourceTarget.GetStateAsync(default);
        state.Messages.ShouldBe((ulong)1);
        (await sourceTarget.LoadAsync(1, default))!.Subject.ShouldBe("agg.orders.created");
    }
}
