#ifndef _H_UTIL_H
#define _H_UTIL_H

#include <SDL_video.h>
#include <random>

namespace UTIL
{ 
	namespace AUDIO {
		constexpr size_t CHUNK_SIZE		= 4096;
		constexpr int		 SAMPLE_RATE	= 44100;
	}

	constexpr float INF_TIME = -99.6875f;
	constexpr auto split = [](const std::string& s, size_t *left, size_t *right, std::string *out) { 
		if ((*right = s.find("/", *left)) != std::string::npos) {
			if (out) {
				*out = s.substr(*left, *right - *left);
			}
			*left = *right + 1;
		} else {
			if (out) {
				out->append(s.substr(*left));
			}
		}
	};

	constexpr auto get_type = [](const std::string& id) {
		auto pos = id.find_last_of("/");
		return (pos != std::string::npos) ? id.substr(pos + 1) : id;
	};

	constexpr auto get_generic = [](const std::string& id) {
		size_t left = 0;
		size_t right = 0;
		std::string out;
		split(id, &left, &right, &out);
		return (out + "/generic/" + get_type(id));
	};

	void flip_surface(SDL_Surface* surface);
	std::string parsePrefix(const std::string& id);

	class RandomGenerator
	{
	public:
		RandomGenerator(float min, float max) :
			rd(),
			gen(rd()),
			dist(min, max) {};
		float genFloat() { return dist(gen); }
	private:
		std::random_device rd;
		std::mt19937 gen;
		std::uniform_real_distribution<float> dist;
	};
}

#endif // _H_UTIL_H
