#pragma once

#include "../llm/ToolRegistry.hpp"
#include <nlohmann/json.hpp>
#include <memory>
#include <vector>

// Forward declarations
namespace celuna {
    class LLMService;
    class StorageService;
    class VoiceService;
}

namespace celuna::tools {

using json = nlohmann::json;

/**
 * @brief MCP Server Tools - Bridge between MCP Server and Celuna services
 *
 * Provides tool definitions for Celuna modules exposed via MCP Server:
 * - chat_with_celuna: Dialogue with Celuna (Claude Sonnet 4)
 * - transcribe_audio: Speech-to-text (Whisper.cpp/OpenAI/Google)
 * - text_to_speech: Text-to-speech synthesis
 * - save_memory: Save note/memory to storage
 * - search_memories: Search stored memories
 *
 * Note: These tools run in synchronous mode (no IIO pub/sub, no main loop)
 */
class MCPServerTools {
public:
    /**
     * @brief Construct MCP server tools with service dependencies
     *
     * @param llm LLMService for chat_with_celuna (can be nullptr)
     * @param storage StorageService for save/search memories (can be nullptr)
     * @param voice VoiceService for TTS/STT (can be nullptr)
     */
    MCPServerTools(
        LLMService* llm,
        StorageService* storage,
        VoiceService* voice
    );

    /**
     * @brief Get all tool definitions for registration
     *
     * @return Vector of ToolDefinition structs
     */
    std::vector<ToolDefinition> getToolDefinitions();

    /**
     * @brief Execute a tool by name
     *
     * @param toolName Tool to execute
     * @param input Tool arguments (JSON)
     * @return Tool result (JSON)
     */
    json execute(const std::string& toolName, const json& input);

private:
    // Tool handlers
    json handleChatWithCeluna(const json& input);
    json handleTranscribeAudio(const json& input);
    json handleTextToSpeech(const json& input);
    json handleSaveMemory(const json& input);
    json handleSearchMemories(const json& input);

    // Service references (nullable)
    LLMService* m_llmService;
    StorageService* m_storageService;
    VoiceService* m_voiceService;
};

} // namespace celuna::tools
