#include "bootstrap/modules/ItemModule.h"

#include "foundation/diagnostics/ExecutionPath.h"

namespace ta::bootstrap::modules
{
    ItemModule::ItemModule(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.items",
                                   "runtime.game.tick.items",
                                   "runtime.raid.reset.items"))
    {
        actions.bind("item.open_item_selector", [this](const ta::application::CommandContext& command)
        {
            feature_.open_selector();
            ta::foundation::execution_path::complete(command.trace_id, "ItemModule", "item selector opened");
        });
        actions.bind("item.create_item", [this](const ta::application::CommandContext& command)
        {
            feature_.request_action({ta::features::items::contracts::PendingAction::CreateItem, command.trace_id});
        });
        actions.bind("item.transit_item", [this](const ta::application::CommandContext& command)
        {
            feature_.request_action({ta::features::items::contracts::PendingAction::TransitItem, command.trace_id});
        });
    }
    ta::features::items::contracts::IItemQueries& ItemModule::queries() noexcept { return feature_; }
    ta::features::items::contracts::IItemCommands& ItemModule::commands() noexcept { return feature_; }
    ta::features::items::ItemDiagnosticsSnapshot ItemModule::diagnostics_snapshot() const noexcept
    {
        return feature_.diagnostics_snapshot();
    }
}
