#pragma once

#include "RuntimeShaderArtifact.h"
#include "RuntimeSlangShaderCompiler.h"

#include <atomic>
#include <functional>
#include <string>
#include <thread>

class RuntimeShaderBridge
{
public:
	using ArtifactCallback = std::function<void(const RuntimeShaderArtifact&)>;
	using ErrorCallback = std::function<void(const std::string&)>;

	RuntimeShaderBridge() = default;
	RuntimeShaderBridge(const RuntimeShaderBridge&) = delete;
	RuntimeShaderBridge& operator=(const RuntimeShaderBridge&) = delete;
	~RuntimeShaderBridge();

	void Start(const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
	void Stop();

private:
	void ThreadMain();

	RuntimeSlangShaderCompiler mCompiler;
	std::thread mThread;
	std::atomic<bool> mStopping{ false };
	ArtifactCallback mOnArtifactReady;
	ErrorCallback mOnError;
};
