#pragma once

#include <atomic>
#include <chrono>
#include <string>

/**
 * Generate a unique persistent identifier.
 * The value is generated once and should be stored in a component field;
 * it will survive scene save/load because it is serialized with the component.
 */
inline std::string generatePersistentId()
{
	static std::atomic<uint64_t> s_counter{ 0 };

	uint64_t counter = ++s_counter;
	uint64_t timestamp = static_cast<uint64_t>(
		std::chrono::high_resolution_clock::now()
			.time_since_epoch()
			.count());

	return "id_" + std::to_string(timestamp) + "_" +
	       std::to_string(counter);
}
