#ifndef EDITSCENE_TERRAIN_TESTS_HPP
#define EDITSCENE_TERRAIN_TESTS_HPP
#pragma once

#include <string>
#include <vector>
#include <functional>
#include <Ogre.h>

class TerrainSystem;
class EditorApp;

/**
 * @file TerrainTests.hpp
 * @brief Automated terrain test runner.
 *
 * Runs a series of terrain editing operations in a loop, verifying:
 *   - Heightmap data changes after sculpt operations
 *   - Terrain page geometry updates (AABB changes)
 *   - Clean create/edit/delete cycles
 *   - Splat painting writes to blend maps
 *   - Memory stability (no leaks, no crashes)
 *
 * Usage:
 * @code
 *   // In main.cpp:
 *   app.initApp();
 *   if (runTerrainTests) {
 *       int result = TerrainTestRunner::run(app, iterations);
 *       app.closeApp();
 *       return result;
 *   }
 * @endcode
 */

struct TerrainTestResult {
	std::string name;
	bool passed = false;
	std::string message;
	int iteration = 0;
};

class TerrainTestRunner {
public:
	/**
	 * Run the full terrain test suite.
	 *
	 * @param app       Initialized EditorApp (must have run initApp()).
	 * @param iterations Number of create/edit/delete cycles (default 10).
	 * @return 0 on success, non-zero on failure.
	 */
	static int run(EditorApp &app, int iterations = 10);

	/**
	 * Tell the test runner whether it is executing in a headless
	 * (no display / offscreen) context.  GPU readback tests will be
	 * skipped when this is true.
	 */
	static void setHeadless(bool headless);

private:
	/* Individual test steps */
	static bool testCreateTerrain(EditorApp &app, TerrainSystem *ts);
	static bool testSculptOperations(EditorApp &app, TerrainSystem *ts);
	static bool testSplatOperations(EditorApp &app, TerrainSystem *ts);
	static bool testVerifyGeometry(EditorApp &app, TerrainSystem *ts);
	static bool testDeleteTerrain(EditorApp &app, TerrainSystem *ts);
	static bool testMemoryStability(EditorApp &app);

	static void logResult(const TerrainTestResult &r);
	static int m_failures;
};

#endif /* EDITSCENE_TERRAIN_TESTS_HPP */
