#pragma once

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <string_view>

#include "core/preview_frame.hpp"

namespace smartcut::core {

class SharedPreviewPublisher {
 public:
  SharedPreviewPublisher();
  ~SharedPreviewPublisher();
  SharedPreviewPublisher(SharedPreviewPublisher&&) noexcept;
  SharedPreviewPublisher& operator=(SharedPreviewPublisher&&) noexcept;
  SharedPreviewPublisher(const SharedPreviewPublisher&) = delete;
  SharedPreviewPublisher& operator=(const SharedPreviewPublisher&) = delete;

  static std::optional<SharedPreviewPublisher> publish(std::string_view mapping_name,
                                                       const PreviewFrame& frame);
  bool valid() const;
  bool acknowledged() const;
  std::uint64_t sequence() const;

 private:
  struct Impl;
  explicit SharedPreviewPublisher(std::unique_ptr<Impl> implementation);
  std::unique_ptr<Impl> implementation_;
};

std::shared_ptr<PreviewFrame> acquire_shared_preview(std::string_view mapping_name);
bool acknowledge_shared_preview(std::string_view mapping_name, std::uint64_t sequence);

}  // namespace smartcut::core
