#pragma once

#include "VideoIOFormat.h"
#include "VideoIOTypes.h"

#include <cstdint>
#include <functional>
#include <string>

namespace RenderCadenceCompositor
{
struct VideoInputEdgeMetrics
{
	uint64_t capturedFrames = 0;
	uint64_t noInputSourceFrames = 0;
	uint64_t unsupportedFrames = 0;
	uint64_t submitMisses = 0;
	double convertMilliseconds = 0.0;
	double submitMilliseconds = 0.0;
	const char* captureFormat = "none";
};

class IVideoInputEdge
{
public:
	virtual ~IVideoInputEdge() = default;

	virtual bool Start(std::string& error) = 0;
	virtual void Stop() = 0;
	virtual void ReleaseResources() = 0;
	virtual bool IsInitialized() const = 0;
	virtual bool IsRunning() const = 0;
	virtual VideoIOPixelFormat CapturePixelFormat() const = 0;
	virtual VideoInputEdgeMetrics Metrics() const = 0;
};

struct VideoOutputEdgeMetrics
{
	uint64_t completions = 0;
	uint64_t displayedLate = 0;
	uint64_t dropped = 0;
	uint64_t flushed = 0;
	uint64_t scheduleFailures = 0;
	bool actualBufferedFramesAvailable = false;
	uint64_t actualBufferedFrames = 0;
	double scheduleCallMilliseconds = 0.0;
	bool scheduleLeadAvailable = false;
	int64_t playbackStreamTime = 0;
	uint64_t playbackFrameIndex = 0;
	uint64_t nextScheduleFrameIndex = 0;
	int64_t scheduleLeadFrames = 0;
	uint64_t scheduleRealignmentCount = 0;
};

class IVideoOutputEdge
{
public:
	using CompletionCallback = std::function<void(const VideoIOCompletion&)>;

	virtual ~IVideoOutputEdge() = default;

	virtual bool StartScheduledPlayback(std::string& error) = 0;
	virtual bool ScheduleFrame(const VideoIOOutputFrame& frame) = 0;
	virtual void Stop() = 0;
	virtual void ReleaseResources() = 0;
	virtual const VideoIOState& State() const = 0;
	virtual VideoOutputEdgeMetrics Metrics() const = 0;
};
}
