namespace ZB.MOM.WW.CBDD.Core.Storage;

/// <summary>
///     Narrow storage port for index structures (page operations + allocation only).
/// </summary>
internal interface IIndexStorage
{
    /// <summary>
    ///     Gets or sets the PageSize.
    /// </summary>
    int PageSize { get; }

    /// <summary>
    ///     Executes AllocatePage.
    /// </summary>
    uint AllocatePage();

    /// <summary>
    ///     Executes FreePage.
    /// </summary>
    /// <param name="pageId">The page identifier.</param>
    void FreePage(uint pageId);

    /// <summary>
    ///     Executes ReadPage.
    /// </summary>
    /// <param name="pageId">The page identifier.</param>
    /// <param name="transactionId">The optional transaction identifier.</param>
    /// <param name="destination">The destination buffer.</param>
    void ReadPage(uint pageId, ulong? transactionId, Span<byte> destination);

    /// <summary>
    ///     Executes WritePage.
    /// </summary>
    /// <param name="pageId">The page identifier.</param>
    /// <param name="transactionId">The transaction identifier.</param>
    /// <param name="data">The source page data.</param>
    void WritePage(uint pageId, ulong transactionId, ReadOnlySpan<byte> data);

    /// <summary>
    ///     Executes WritePageImmediate.
    /// </summary>
    /// <param name="pageId">The page identifier.</param>
    /// <param name="data">The source page data.</param>
    void WritePageImmediate(uint pageId, ReadOnlySpan<byte> data);
}