#ifndef EDITSCENE_SAVELOADSYSTEM_HPP
#define EDITSCENE_SAVELOADSYSTEM_HPP
#pragma once

#include <nlohmann/json.hpp>
#include <string>
#include <vector>

/**
 * Save/load system for game-mode saves.
 *
 * Manages save slots in an OS-dependent user data directory:
 *   Linux:   ~/.local/share/World2/saves/
 *   Windows: %APPDATA%/World2/saves/
 *   macOS:   ~/Library/Application Support/World2/saves/
 *
 * Each slot is a single JSON file containing:
 *   - Save metadata (base scene, timestamp, play time, slot name)
 *   - CharacterRegistry state
 *   - ContainerStateRegistry state
 *   - ItemStateRegistry state
 *   - Runtime entity component overrides
 *   - Lua callback data
 */
class SaveLoadSystem {
public:
	struct SaveInfo {
		std::string path;
		std::string filename;
		std::string slotName;
		std::string timestamp;
		float playTime = 0.0f;
		std::string baseScene;
	};

	/**
	 * Get the OS-dependent save directory.
	 * Creates the directory if it doesn't exist.
	 */
	static std::string getSaveDirectory();

	/**
	 * List all existing save files in the save directory.
	 */
	static std::vector<SaveInfo> listSaves();

	/**
	 * Generate a unique filename for a new save.
	 */
	static std::string generateSaveFilename();

	/**
	 * Delete a save file.
	 */
	static bool deleteSave(const std::string &path);

	/**
	 * Write a save file.
	 */
	static bool writeSaveFile(const std::string &path,
				  const nlohmann::json &data);

	/**
	 * Read a save file.
	 */
	static bool readSaveFile(const std::string &path,
				 nlohmann::json &outData);

	/**
	 * Get current ISO-8601 timestamp string.
	 */
	static std::string getCurrentTimestamp();
};

#endif // EDITSCENE_SAVELOADSYSTEM_HPP
