#pragma once

#include "ILLMProvider.hpp"
#include "../http/HttpClient.hpp"
#include <spdlog/spdlog.h>
#include <memory>

namespace celuna {

/**
 * @brief Anthropic Claude API provider
 *
 * Supports Claude models with native tool use.
 * Response format uses tool_use/tool_result content blocks.
 */
class ClaudeProvider : public ILLMProvider {
public:
    explicit ClaudeProvider(const json& config);
    ~ClaudeProvider() override = default;

    LLMResponse chat(const std::string& systemPrompt,
                     const json& messages,
                     const json& tools) override;

    json formatToolResults(const std::vector<ToolResult>& results) override;

    void appendAssistantMessage(json& messages, const LLMResponse& response) override;

    std::string getProviderName() const override { return "claude"; }
    void setModel(const std::string& model) override { m_model = model; }
    void setMaxTokens(int maxTokens) override { m_maxTokens = maxTokens; }
    std::string getModel() const override { return m_model; }

private:
    std::string m_apiKey;
    std::string m_model = "claude-sonnet-4-20250514";
    std::string m_baseUrl = "https://api.anthropic.com";
    int m_maxTokens = 4096;

    std::unique_ptr<HttpClient> m_client;
    std::shared_ptr<spdlog::logger> m_logger;

    // Convert tools to Claude format
    json convertTools(const json& tools);

    // Parse Claude response
    LLMResponse parseResponse(const json& response);

    // Build assistant message content from response
    json buildAssistantContent(const LLMResponse& response);
};

} // namespace celuna
