//
// GamePhaseRunner - Unified logic for running game phases with AI decision-making
// Used by both AI Performance Runner and AI Battle Simulator
//

#ifndef EAGLE0_GAME_PHASE_RUNNER_HPP
#define EAGLE0_GAME_PHASE_RUNNER_HPP

#include <functional>

#include "src/main/cpp/net/eagle0/shardok/library/GameStateW.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/ShardokCTypes.h"

namespace shardok {

// Forward declarations
class ShardokEngine;
class ShardokAIClient;

namespace ai_testing_common {

/**
 * Result of running a game phase.
 */
struct PhaseResult {
    int commandsExecuted = 0;
    bool gameEnded = false;
};

/**
 * Helper class for running setup and battle phases with AI decision-making.
 *
 * This centralizes the game phase execution logic that was duplicated
 * between AI Performance Runner and AI Battle Simulator.
 */
class GamePhaseRunner {
public:
    /**
     * Run the setup phase where AIs place their units.
     *
     * @param engine The game engine
     * @param getAI Function to get the AI client for a given player ID
     * @return PhaseResult with number of commands executed and whether game ended
     */
    static auto RunSetupPhase(
            ShardokEngine& engine,
            const std::function<ShardokAIClient&(PlayerId)>& getAI) -> PhaseResult;

    /**
     * Run one turn of a game phase (either for AI testing or full battle).
     *
     * @param engine The game engine
     * @param playerId The player whose turn it is
     * @param ai The AI client to use for decision-making
     * @return True if the turn was executed successfully, false if no commands available
     */
    static auto RunSingleTurn(ShardokEngine& engine, PlayerId playerId, ShardokAIClient& ai)
            -> bool;
};

}  // namespace ai_testing_common
}  // namespace shardok

#endif  // EAGLE0_GAME_PHASE_RUNNER_HPP
