namespace NATS.Server.JetStream.Storage;

// Go: server/store.go:71
/// <summary>
/// Reusable message container returned by store load operations.
/// The internal buffer is reused across calls to avoid allocations on the hot path.
/// Mirrors Go's StoreMsg struct, which pools a single backing byte slice (buf) that
/// both hdr and msg slice into.
/// </summary>
public sealed class StoreMsg
{
    // Go: StoreMsg.subj
    public string Subject { get; set; } = string.Empty;

    // Go: StoreMsg.hdr — NATS message headers (optional)
    public byte[]? Header { get; set; }

    // Go: StoreMsg.msg — message body
    public byte[]? Data { get; set; }

    // Go: StoreMsg.seq — stream sequence number
    public ulong Sequence { get; set; }

    // Go: StoreMsg.ts — wall-clock timestamp in Unix nanoseconds
    public long Timestamp { get; set; }

    /// <summary>
    /// Resets all fields to their zero values while retaining the backing buffer
    /// for reuse by the next load call. Matches Go's StoreMsg.clear().
    /// </summary>
    public void Clear()
    {
        Subject = string.Empty;
        Header = null;
        Data = null;
        Sequence = 0;
        Timestamp = 0;
    }
}
