#pragma once

#include "IOBridge.hpp"
#include "../llm/ToolRegistry.hpp"

#include <grove/IIO.h>
#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>

#include <vector>
#include <memory>

namespace celuna {

using json = nlohmann::json;

/**
 * @brief Internal tools that communicate with GroveEngine modules via IIO
 *
 * These tools allow the LLM to interact with:
 * - SchedulerModule: tasks, breaks, hyperfocus
 * - MonitoringModule: app usage, focus stats
 * - StorageModule: notes, history
 * - VoiceModule: TTS control
 */
class InternalTools {
public:
    explicit InternalTools(grove::IIO* io);

    /**
     * @brief Get all tool definitions for registration
     */
    std::vector<ToolDefinition> getTools() const;

    /**
     * @brief Process incoming responses from modules
     *
     * Call this in the service's process loop
     */
    void processResponses();

    /**
     * @brief Get number of registered tools
     */
    size_t size() const { return m_tools.size(); }

private:
    grove::IIO* m_io;
    std::unique_ptr<IOBridge> m_bridge;
    std::shared_ptr<spdlog::logger> m_logger;
    std::vector<ToolDefinition> m_tools;

    // Tool implementations
    json getCurrentTask(const json& input);
    json listTasks(const json& input);
    json startTask(const json& input);
    json completeTask(const json& input);
    json startBreak(const json& input);
    json getFocusStats(const json& input);
    json getCurrentApp(const json& input);
    json saveNote(const json& input);
    json queryNotes(const json& input);
    json getSessionHistory(const json& input);
    json speak(const json& input);

    // Helper to create tool definitions
    void registerTools();
};

} // namespace celuna
