using System;
using System.Threading;
using System.Threading.Tasks;
namespace Timeline.Services.Data
{
    /// 
    /// A data manager controlling data.
    /// 
    /// 
    /// Identical data will be saved as one copy and return the same tag.
    /// Every data has a ref count. When data is retained, ref count increase.
    /// When data is freed, ref count decease. If ref count is decreased
    /// to 0, the data entry will be destroyed and no longer occupy space.
    /// 
    public interface IDataManager
    {
        /// 
        /// Saves the data to a new entry if it does not exist, 
        /// increases its ref count and returns a tag to the entry.
        /// 
        /// The data. Can't be null.
        /// Cancellation token.
        /// The tag of the created entry.
        /// Thrown when  is null.
        public Task RetainEntryAsync(byte[] data, CancellationToken cancellationToken = default);
        /// 
        /// Decrease the the ref count of the entry.
        /// Remove it if ref count is zero.
        /// 
        /// The tag of the entry.
        /// Cancellation token.
        /// Thrown when  is null.
        /// 
        /// It's no-op if entry with tag does not exist.
        /// 
        public Task FreeEntryAsync(string tag, CancellationToken cancellationToken = default);
        /// 
        /// Retrieve the entry with given tag. If not exist, returns null.
        /// 
        /// The tag of the entry.
        /// Cancellation token.
        /// The data of the entry. If not exist, returns null.
        /// Thrown when  is null.
        public Task GetEntryAsync(string tag, CancellationToken cancellationToken = default);
    }
}