#ifndef HIK_CAMERA_RECORDER_HPP_
#define HIK_CAMERA_RECORDER_HPP_

// std
#include <atomic>
#include <condition_variable>
#include <deque>
#include <filesystem>
#include <mutex>
#include <thread>
#include <vector>

// OpenCV
#include <opencv2/videoio.hpp>

namespace fyt::camera_driver {
class Recorder {
public:
  using Frame = std::vector<unsigned char>;

  Recorder(const std::filesystem::path &file, int fps, cv::Size size);
  ~Recorder();

  void addFrame(const Frame &frame);
  void start();
  void stop();

  std::filesystem::path path;

private:
  void recorderThread();

  cv::Size size_;
  int fps_;
  cv::VideoWriter writer_;

  std::deque<Frame> frame_queue_;

  std::mutex mutex_;
  std::atomic<bool> recording_{false};
  std::condition_variable cv_;
  std::thread recorder_thread_;
};
}  // namespace fyt::camera_driver

#endif  // HIK_CAMERA_RECORDER_HPP_
