using NATS.Server.JetStream.Storage;

namespace NATS.Server.JetStream.Tests;

public class JetStreamFileStoreCryptoCompressionTests
{
    [Fact]
    public async Task File_store_compression_and_encryption_roundtrip_preserves_payload()
    {
        var dir = Path.Combine(Path.GetTempPath(), $"natsdotnet-filestore-crypto-{Guid.NewGuid():N}");
        try
        {
            await using var store = new FileStore(new FileStoreOptions
            {
                Directory = dir,
                EnableCompression = true,
                EnableEncryption = true,
                EncryptionKey = [1, 2, 3, 4],
            });

            var payload = Enumerable.Repeat((byte)'a', 512).ToArray();
            var seq = await store.AppendAsync("orders.created", payload, default);
            var loaded = await store.LoadAsync(seq, default);
            loaded.ShouldNotBeNull();
            loaded.Payload.ToArray().ShouldBe(payload);
        }
        finally
        {
            if (Directory.Exists(dir))
                Directory.Delete(dir, recursive: true);
        }
    }
}
