//
// Self-Play Battle Runner - Runs battles with state recording for ML training
//

#ifndef EAGLE0_SELF_PLAY_BATTLE_RUNNER_HPP
#define EAGLE0_SELF_PLAY_BATTLE_RUNNER_HPP

#include "StateRecorder.hpp"
#include "src/main/cpp/net/eagle0/shardok/ai/ShardokAIClient.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/ShardokEngine.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/settings/GameSettings.hpp"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
#include "src/main/protobuf/net/eagle0/shardok/ai_battle_simulator/ai_battle_config.pb.h"
#pragma clang diagnostic pop

namespace shardok {
namespace ml {

struct SelfPlayResult {
    PlayerId winner;
    int totalRounds;
    int totalCommands;
    int statesRecorded;
    std::string description;
};

/**
 * @brief Runs a complete battle with state recording for ML training.
 *
 * This class duplicates the core game loop from AiBattleSimulator
 * but adds StateRecorder integration to capture game states.
 */
class SelfPlayBattleRunner {
public:
    explicit SelfPlayBattleRunner(
            const net::eagle0::shardok::ai_battle_simulator::BattleConfig& config,
            GameSettingsSPtr settings);

    /**
     * @brief Run a complete battle and record states for ML training.
     *
     * @param recorder The StateRecorder to write game states to
     * @param aiAlgorithm Which AI algorithm to use for both players
     * @param verbose Whether to print detailed progress
     * @return Battle result including winner and statistics
     */
    SelfPlayResult
    RunBattleWithRecording(StateRecorder& recorder, AIAlgorithmType aiAlgorithm, bool verbose);

private:
    const net::eagle0::shardok::ai_battle_simulator::BattleConfig config_;
    GameSettingsSPtr gameSettings_;

    /**
     * @brief Run the battle phase with state recording.
     */
    SelfPlayResult RunBattlePhaseWithRecording(
            ShardokEngine& engine,
            ShardokAIClient& attackerAI,
            ShardokAIClient& defenderAI,
            StateRecorder& recorder,
            bool verbose);
};

}  // namespace ml
}  // namespace shardok

#endif  // EAGLE0_SELF_PLAY_BATTLE_RUNNER_HPP
