#pragma once

#include <Ogre.h>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
#include <random>

struct FurnitureDefinition {
	std::string name;
	std::string meshName;
	std::vector<std::string> tags;
	nlohmann::json jsonData;
};

class FurnitureLibrary {
public:
	static FurnitureLibrary &getInstance();

	void loadAll();
	bool isLoaded() const { return m_loaded; }
	void reload() { m_loaded = false; loadAll(); }

	const std::vector<FurnitureDefinition> &getDefinitions() const;

	const FurnitureDefinition *findByName(const std::string &name) const;

	std::vector<const FurnitureDefinition *> findByTags(
		const std::vector<std::string> &requiredTags,
		const std::vector<std::string> &forbiddenTags = {}) const;

	const FurnitureDefinition *selectByTags(
		const std::vector<std::string> &requiredTags,
		std::mt19937 &rng,
		const std::vector<std::string> &forbiddenTags = {}) const;

private:
	FurnitureLibrary() = default;
	std::vector<FurnitureDefinition> m_definitions;
	bool m_loaded = false;
};
