#pragma once

#include "RenderFrameState.h"
#include "RenderStateComposer.h"
#include "RuntimeSnapshotProvider.h"

#include <cstdint>
#include <vector>

class RenderFrameStateResolver
{
public:
	explicit RenderFrameStateResolver(RuntimeSnapshotProvider& runtimeSnapshotProvider);

	void StoreCommittedSnapshot(
		const RuntimeRenderStateSnapshot& snapshot,
		const std::vector<RuntimeRenderState>& committedLayerStates);
	bool Resolve(
		const RenderFrameInput& input,
		const std::vector<RuntimeRenderState>& committedLayerStates,
		RuntimeLiveState& liveState,
		std::vector<RuntimeLiveOscCommitRequest>* commitRequests,
		RenderFrameState& frameState);

private:
	std::vector<RuntimeRenderState> ComposeLayerStates(
		const std::vector<RuntimeRenderState>& baseStates,
		RuntimeLiveState& liveState,
		bool allowCommit,
		double smoothing,
		std::vector<RuntimeLiveOscCommitRequest>* commitRequests) const;

	RuntimeSnapshotProvider& mRuntimeSnapshotProvider;
	RenderStateComposer mRenderStateComposer;
	std::vector<RuntimeRenderState> mCachedLayerRenderStates;
	uint64_t mCachedRenderStateVersion = 0;
	uint64_t mCachedParameterStateVersion = 0;
	unsigned mCachedRenderStateWidth = 0;
	unsigned mCachedRenderStateHeight = 0;
};
