#pragma once

#include "../../../include/dv-processing/data/frame_base.hpp"

#include <pybind11/pybind11.h>

namespace py = pybind11;

/**
 * @brief Bind FrameSource and Frame classes to python
 * @param m pybind The module to bind to
 */
void bind_frame_base(py::module &m) {
	// Bind dv::FrameSource
	{
		py::enum_<dv::FrameSource> frameSource(m, "FrameSource");
		for (auto enumValue = static_cast<int8_t>(dv::FrameSource::MIN);
			static_cast<dv::FrameSource>(enumValue) <= dv::FrameSource::MAX; enumValue++) {
			auto currentEnum = static_cast<dv::FrameSource>(enumValue);
			frameSource.value(dv::EnumNameFrameSource(currentEnum), currentEnum);
		}
	}

	// Bind dv::Frame
	py::class_<dv::Frame>(m, "Frame", "A class containing a frame image with timestamp and additional metadata")
		.def(py::init<>(), "Constructs an empty image")
		.def(py::init<int64_t, const cv::Mat &>(), py::arg("timestamp"), py::arg("image"),
			"Minimal constructor defining only a timestamp and image contents")
		.def(py::init<int64_t, int64_t, int16_t, int16_t, const cv::Mat &, dv::FrameSource>(), py::arg("timestamp"),
			py::arg("exposure"), py::arg("positionX"), py::arg("positionY"), py::arg("image"), py::arg("source"),
			"Full constructor")
		.def_readwrite("image", &dv::Frame::image, "Image contents")
		.def_readwrite(
			"timestamp", &dv::Frame::timestamp, "Capture time of the image, usually refers to start of exposure")
		.def_readwrite("exposure", &dv::Frame::exposure, "Time duration of exposure for this image")
		.def_readwrite("source", &dv::Frame::source, "Definition of source of the image")
		.def_readwrite("positionX", &dv::Frame::positionX, "X coordinate if the image is a crop")
		.def_readwrite("positionY", &dv::Frame::positionY, "X coordinate if the image is a crop")
		.def(
			"time",
			[](const dv::Frame &self) {
				return dv::toTimePoint(self.timestamp);
			},
			"Timestamp of the captured data, compatible with python time library");
}
