import { algodTools, handleAlgodTools } from './algod/index.js';
import { indexerTools, handleIndexerTools } from './indexer/index.js';
import { nfdTools, handleNFDTools } from './nfd/index.js';
// import { vestigeTools, handleVestigeTools } from './vestige/index.js';
import { tinymanTools, handleTinymanTools } from './tinyman/index.js';
// import { ultradeTools, handleUltradeTools } from './ultrade/index.js';
import { haystackTools, handleHaystackTools } from './hayrouter/index.js';
import { peraTools, handlePeraTools } from './pera/index.js';
import { alphaTools, handleAlphaTools } from './alpha/index.js';
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
import { ResponseProcessor } from '../../utils/responseProcessor.js';
// Combine all API tools
export const apiManager = [
    ...algodTools,
    ...indexerTools,
    ...nfdTools,
    ...tinymanTools,
    ...haystackTools,
    ...peraTools,
    ...alphaTools
];
// Handle all API tools
export async function handleApiManager(name, args) {
    try {
        let response;
        // Tinyman tools
        if (name.startsWith('api_tinyman_')) {
            response = await handleTinymanTools(name, args);
        }
        // NFD tools
        else if (name.startsWith('api_nfd_')) {
            response = await handleNFDTools(name, args);
        }
        // Indexer tools
        else if (name.startsWith('api_indexer_')) {
            response = await handleIndexerTools(name, args);
        }
        // Algod tools
        else if (name.startsWith('api_algod_')) {
            response = await handleAlgodTools(name, args);
        }
        // Haystack Router tools
        else if (name.startsWith('api_haystack_')) {
            response = await handleHaystackTools(name, args);
        }
        // Pera Wallet tools
        else if (name.startsWith('api_pera_')) {
            response = await handlePeraTools(name, args);
        }
        // Alpha Arcade tools
        else if (name.startsWith('alpha_')) {
            response = await handleAlphaTools(name, args);
        }
        else {
            throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
        }
        // Process and format the response
        return ResponseProcessor.processResponse(response, args?.pageToken, args?.itemsPerPage);
    }
    catch (error) {
        if (error instanceof McpError) {
            throw error;
        }
        throw new McpError(ErrorCode.InternalError, `Failed to handle resource tool: ${error instanceof Error ? error.message : String(error)}`);
    }
}
