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

namespace NATS.Server.Tests;

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

        var message = new StoredMessage
        {
            Sequence = 10,
            Subject = "orders.created",
            Payload = "ok"u8.ToArray(),
            TimestampUtc = DateTime.UtcNow,
        };

        await mirror.OnOriginAppendAsync(message, default);
        await source.OnOriginAppendAsync(message, default);

        mirror.LastOriginSequence.ShouldBe((ulong)10);
        source.LastOriginSequence.ShouldBe((ulong)10);

        var sourced = await sourceTarget.LoadAsync(1, default);
        sourced.ShouldNotBeNull();
        sourced.Subject.ShouldBe("agg.orders.created");
    }
}
