//
// Temporary AI experiment switches used by benchmark-only EXPERIMENTAL runs.
//

#ifndef EAGLE0_SHARDOK_AI_AI_EXPERIMENT_CONFIG_HPP
#define EAGLE0_SHARDOK_AI_AI_EXPERIMENT_CONFIG_HPP

#include <charconv>
#include <cstdlib>
#include <string_view>
#include <system_error>

namespace shardok {

[[nodiscard]] inline auto CurrentAIExperimentId() -> int {
    const char* rawValue = std::getenv("SHARDOK_SCORING_EXPERIMENT_ID");
    if (rawValue == nullptr) { return 0; }

    const std::string_view value(rawValue);
    if (value.empty()) { return 0; }

    int experimentId = 0;
    const auto parseResult =
            std::from_chars(value.data(), value.data() + value.size(), experimentId);
    if (parseResult.ec != std::errc{} || parseResult.ptr != value.data() + value.size()) {
        return 0;
    }
    return experimentId;
}

[[nodiscard]] inline auto IsAIExperiment(const int id) -> bool {
    return CurrentAIExperimentId() == id;
}

}  // namespace shardok

#endif  // EAGLE0_SHARDOK_AI_AI_EXPERIMENT_CONFIG_HPP
