//
// GameSettingsFactory Implementation
//

#include "GameSettingsFactory.hpp"

#include "src/main/cpp/net/eagle0/common/FilesystemUtils.hpp"
#include "src/main/cpp/net/eagle0/common/TsvParser.hpp"
#include "src/main/cpp/net/eagle0/common/byte_vector.hpp"
#include "src/main/cpp/net/eagle0/shardok/util/BattalionTypeRegistrar.hpp"

namespace shardok {
namespace ai_testing_common {

auto GameSettingsFactory::CreateDefault() -> GameSettingsSPtr {
    auto settings = std::make_shared<GameSettings>();
    auto setter = settings->GetSetter();

    // Load battalion types
    BattalionTypeRegistrar::RegisterBattalionTypes(setter);

    // Load settings from settings.tsv file
    const std::string settingsPath =
            FilesystemUtils::StaticShardokFilesDirectory() + "settings.tsv";
    const std::string settingsTsv = std::string(byte_vector::FromPath(settingsPath));

    TsvParser parser;
    const auto valuesAndTypes = parser.ParseColumnEntryTsv(settingsTsv);
    setter.SetFromTypesAndValues(valuesAndTypes[1], valuesAndTypes[0]);

    return settings;
}

}  // namespace ai_testing_common
}  // namespace shardok
