using Inspectron.Fastbuffer.Interfaces;
using OpenCvSharp;

namespace Inspectron.Fastbuffer;

public class IsolatedRingbuffer: IDisposable
{
    private readonly string _path;
    private readonly int _bufferSize;
    private readonly IFilesystem _filesystem;
    private readonly string _indexPath;
    private readonly IndexFile _index;

    public const string BufferDirectory = ".rb";
    public const string IndexFile = "index.idx";

    public IsolatedRingbuffer(string path, int bufferSize, IFilesystem filesystem)
    {
        _path = path;
        _bufferSize = bufferSize;
        _filesystem = filesystem;

        _indexPath = Path.Combine(_path, BufferDirectory,IndexFile );
        Directory.CreateDirectory(Path.Combine(_path, BufferDirectory));

        _index = new IndexFile(_indexPath, _bufferSize, _filesystem);

    }

    public void Write(Mat data, string fileName)
    {
        _index.WriteNextArtifact(data, fileName);
    }

    public void Dispose()
    {
        _filesystem.Dispose();
    }
}