#ifndef TIMER_H
#define TIMER_H

#include <chrono>
#include <string>
#include "easylogging++/easylogging++.h"

class Timer
{
public:
	std::chrono::time_point<std::chrono::high_resolution_clock> start_time, start_time_local;
	std::chrono::time_point<std::chrono::high_resolution_clock> end_time, end_time_local;
	std::string msg;
	std::string local_msg;

	Timer()
	{
		msg = "Scope execution time : ";
		start_time = std::chrono::high_resolution_clock::now();
	}

	void setMessage(std::string text)
	{
		msg = text;
	}

	void start(std::string text)
	{
		local_msg = text;
		start_time_local = std::chrono::high_resolution_clock::now();
	}

	void stop()
	{
		end_time_local = std::chrono::high_resolution_clock::now();
		std::cout << local_msg << " " << std::chrono::duration_cast<std::chrono::duration<float>>(end_time_local - start_time_local).count() << " s." << std::endl;;
	}

	std::chrono::duration<float> duration_s()
	{
		end_time = std::chrono::high_resolution_clock::now();
		return std::chrono::duration_cast<std::chrono::duration<float>>(end_time - start_time);
	}

	~Timer()
	{
		end_time = std::chrono::high_resolution_clock::now();
		LOG(INFO) << msg << " " << std::chrono::duration_cast<std::chrono::duration<float>>(end_time - start_time).count() << " s.\n";
	}
};

#endif // TIMER_H