//
// Created by Dan Crosby on 11/26/22.
//

#include <include/gtest/gtest.h>

#include "src/main/cpp/net/eagle0/shardok/library/action_point_distances/ActionPointDistances.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/action_point_distances/FixedActionPointDistances.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/fb_helpers/HexMapHelpers.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/settings_loader/SettingsLoader.hpp"
#include "src/main/cpp/net/eagle0/shardok/util/MapLoader.hpp"

using namespace std::chrono;
using namespace shardok;

auto main(int argc, char** argv) -> int {
    FilesystemUtils::SetExecPath(
            "/Users/dancrosby/CodingProjects/github/eagle0/bazel-bin/src/main/cpp/net/eagle0/"
            "shardok/library/action_point_distances/fixed_action_point_distances_timer_app");
    const auto gameSettings = SettingsLoader::LoadSettings();

    const vector<string> mapNames = GetMapNames();
    vector<HexMapW> hexMaps;

    for (const string& name : mapNames) {
        auto hexMapProto = LoadMap(name);
        flatbuffers::FlatBufferBuilder fbb;
        const auto offset = shardok::fb::ConvertHexMapProto(fbb, hexMapProto);
        fbb.Finish(offset);

        hexMaps.emplace_back(fbb);
    }

    const auto& battalionType = gameSettings->GetGetter().GetBattalionType(
            net::eagle0::shardok::storage::fb::BattalionTypeId_LIGHT_INFANTRY);

    const auto start = system_clock::now();

    for (int i = 0; i < 100; i++) {
        for (const HexMapW& hexMap : hexMaps) {
            shardok::FixedActionPointDistances
                    distances(hexMap, 0x1234, 0xABCD, battalionType, true, 5);
        }
    }
    const auto end = system_clock::now();

    std::cerr << duration_cast<microseconds>(end - start).count() << " µs" << std::endl;
}