#ifndef EDITSCENE_LUA_SAVELOAD_API_HPP
#define EDITSCENE_LUA_SAVELOAD_API_HPP
#pragma once

#include <lua.hpp>
#include <nlohmann/json.hpp>

namespace editScene
{

/**
 * @brief Register save/load callback Lua API functions into the "ecs" table.
 *
 * Adds:
 *   ecs.register_save_callback(name, function() return table end)
 *   ecs.register_load_callback(name, function(table) end)
 *
 * @param L The Lua state.
 */
void registerLuaSaveLoadApi(lua_State *L);

/**
 * @brief Call all registered Lua save callbacks and collect their data.
 * @param L Lua state.
 * @return JSON object keyed by callback name.
 */
nlohmann::json collectLuaSaveData(lua_State *L);

/**
 * @brief Call all registered Lua load callbacks with saved data.
 * @param L Lua state.
 * @param data JSON object keyed by callback name.
 */
void applyLuaLoadData(lua_State *L, const nlohmann::json &data);

/**
 * @brief Convert a Lua table at the given stack index to JSON.
 */
nlohmann::json luaTableToJson(lua_State *L, int index);

/**
 * @brief Push a JSON value onto the Lua stack as a table/value.
 */
void jsonToLuaValue(lua_State *L, const nlohmann::json &j);

} // namespace editScene

#endif // EDITSCENE_LUA_SAVELOAD_API_HPP
