#include "bootstrap/modules/WorldModule.h"

#include "adapters/eft/items/catalog/ItemTemplateCatalogService.h"

namespace ta::bootstrap::modules
{
    WorldModule::WorldModule(ta::adapters::eft::runtime::EftGameContext& context,
                             ta::adapters::eft::items::WishlistService& wishlist_service,
                             ta::adapters::eft::items::ItemTemplateCatalogService& item_catalog_service,
                             ta::application::UiActionDispatcher& actions)
        : gateway_(context, wishlist_service, item_catalog_service),
          feature_(gateway_, settings_),
          ports_(ModulePorts::bind(feature_, &settings_,
                                   "runtime.application.tick.world",
                                   "runtime.game.tick.world",
                                   "runtime.raid.reset.world"))
    {
        const auto bind = [this, &actions](const char* key, const ta::features::world::WorldCommandType type)
        {
            actions.bind(key, [this, type](const ta::application::CommandContext& command)
            {
                feature_.submit({type, command.trace_id});
            });
        };
        bind("world.unlock_doors", ta::features::world::WorldCommandType::UnlockDoors);
        bind("world.teleport_normal_items", ta::features::world::WorldCommandType::TeleportNormalItems);
        bind("world.teleport_wishlist_items", ta::features::world::WorldCommandType::TeleportWishlistItems);
        bind("world.teleport_quest_items", ta::features::world::WorldCommandType::TeleportQuestItems);
        bind("world.teleport_corpses", ta::features::world::WorldCommandType::TeleportCorpses);
    }
    ta::features::world::WorldDiagnosticsSnapshot WorldModule::diagnostics_snapshot() const noexcept
    {
        return feature_.diagnostics_snapshot();
    }
}
