#pragma once

#include <filesystem>
#include <string>

class RuntimeConfigStore
{
public:
	struct AppConfig
	{
		std::string shaderLibrary = "shaders";
		unsigned short serverPort = 8080;
		unsigned short oscPort = 9000;
		std::string oscBindAddress = "127.0.0.1";
		double oscSmoothing = 0.18;
		bool autoReload = true;
		unsigned maxTemporalHistoryFrames = 4;
		unsigned previewFps = 30;
		bool enableExternalKeying = false;
		std::string inputVideoFormat = "1080p";
		std::string inputFrameRate = "59.94";
		std::string outputVideoFormat = "1080p";
		std::string outputFrameRate = "59.94";
	};

	bool Initialize(std::string& error);

	const AppConfig& GetConfig() const;
	const std::filesystem::path& GetRepoRoot() const;
	const std::filesystem::path& GetUiRoot() const;
	const std::filesystem::path& GetDocsRoot() const;
	const std::filesystem::path& GetShaderRoot() const;
	const std::filesystem::path& GetRuntimeRoot() const;
	const std::filesystem::path& GetPresetRoot() const;
	const std::filesystem::path& GetRuntimeStatePath() const;
	const std::filesystem::path& GetWrapperPath() const;
	const std::filesystem::path& GetGeneratedGlslPath() const;
	const std::filesystem::path& GetPatchedGlslPath() const;
	void SetBoundControlServerPort(unsigned short port);

private:
	bool ResolvePaths(std::string& error);
	bool LoadConfig(std::string& error);
	std::string ReadTextFile(const std::filesystem::path& path, std::string& error) const;
	void RefreshConfigDependentPaths();

	AppConfig mConfig;
	std::filesystem::path mRepoRoot;
	std::filesystem::path mUiRoot;
	std::filesystem::path mDocsRoot;
	std::filesystem::path mShaderRoot;
	std::filesystem::path mRuntimeRoot;
	std::filesystem::path mPresetRoot;
	std::filesystem::path mRuntimeStatePath;
	std::filesystem::path mConfigPath;
	std::filesystem::path mWrapperPath;
	std::filesystem::path mGeneratedGlslPath;
	std::filesystem::path mPatchedGlslPath;
};
