// Copyright 2012-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0

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

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

public sealed class CompressionInfoTests
{
    [Fact]
    public void MarshalMetadata_UnmarshalMetadata_ShouldRoundTrip()
    {
        var ci = new CompressionInfo
        {
            Type = StoreCompression.S2Compression,
            Original = 12345,
            Compressed = 6789,
        };

        var payload = ci.MarshalMetadata();
        payload.Length.ShouldBeGreaterThan(4);

        var copy = new CompressionInfo();
        var consumed = copy.UnmarshalMetadata(payload);

        consumed.ShouldBe(payload.Length);
        copy.Type.ShouldBe(StoreCompression.S2Compression);
        copy.Original.ShouldBe(12345UL);
        copy.Compressed.ShouldBe(6789UL);
    }

    [Fact]
    public void UnmarshalMetadata_InvalidPrefix_ShouldReturnZero()
    {
        var ci = new CompressionInfo();
        ci.UnmarshalMetadata([1, 2, 3, 4]).ShouldBe(0);
    }
}
