//
// Created by Dan Crosby on 07/04/25.
//

#ifndef EAGLE0_AITIMEBUDGET_HPP
#define EAGLE0_AITIMEBUDGET_HPP

#include <atomic>
#include <chrono>
#include <memory>

#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 GameSettings;
using GameSettingsSPtr = std::shared_ptr<GameSettings>;

// RAII counter for tracking concurrent AI command evaluations
class AIEvaluationCounter {
    static std::atomic<int> activeCount;

public:
    AIEvaluationCounter();
    ~AIEvaluationCounter();
    static int GetCurrentCount();
};

// Configuration structure for iterative deepening time budget
struct AITimeBudget {
    std::chrono::milliseconds remainingBudget;  // Time budget remaining (decremented as used)
    int minDepthRequired;                       // Minimum depth from minLookaheadTurns
    bool isCloseToEnemy;                        // Proximity flag for budget selection
};

// Calculate time budget based on proximity to enemies and castles
auto CalculateTimeBudget(
        PlayerId playerId,
        const GameSettingsSPtr &settings,
        const GameStateW &state) -> AITimeBudget;

}  // namespace shardok

#endif  // EAGLE0_AITIMEBUDGET_HPP