#pragma once

#include "misc/messagedata.hpp"
#include "nlohmann/json.hpp"
using json = nlohmann::json;

class ProgressIndicator
{
private:
	int progress;
	std::string guid;
	std::string text;
	std::function<void(messagedata)> sendProgressUpdate;
	
	void updateProgress()
	{
		json outjson;
		outjson["value"] = progress;
		outjson["text"] = text;
		messagedata md(messagedata::level::info_lvl, messagedata::type::progress, outjson.dump());
		md.guid = guid;
		sendProgressUpdate(md);
	}

public:
	ProgressIndicator(std::function<void(messagedata)>& pu, std::string g): sendProgressUpdate(pu), guid(g)
	{
		progress = 0;
		text = "Progress";
	}

	void reset()
	{
		progress = 0;
	}

	void setProgress(int p)
	{
		if (p > 100)
			progress = 100;
		else if (p < 0)
			progress = 0;
		else
			progress = p;

		//updateProgress();
	}


	void setProgress(double p)
	{
		setProgress(std::round(p));
	}

	void setText(std::string t)
	{
		text = t;
	}

	void sendLog(std::string msg)
	{
		messagedata md(messagedata::level::info_lvl, messagedata::type::log, msg);
		sendProgressUpdate(md);
	}

};