#pragma once
// engine_ollama.h — OllamaClient class declaration
// Ported from v1-monolithic/include/ollama.hpp → Iter2 modular architecture
// Uses nlohmann/json instead of jsoncpp

#include "json.hpp"

#include <string>
#include <vector>
#include <map>
#include <mutex>
#include <cstdint>

// Forward declaration — we don't pull in curl headers in the public header
typedef void CURL;

namespace node669427 {
namespace subsys {

struct OllamaMsg {
    std::string role;
    std::string content;
    OllamaMsg() = default;
    OllamaMsg(const std::string& r, const std::string& c) : role(r), content(c) {}
};

struct OllamaResponse {
    std::string response_text;
    bool done = false;
    uint64_t eval_count = 0;
    uint64_t total_duration = 0;
};

class OllamaClient {
public:
    explicit OllamaClient(const std::string& base_url = "http://127.0.0.1:11434");
    ~OllamaClient();

    OllamaClient(const OllamaClient&) = delete;
    OllamaClient& operator=(const OllamaClient&) = delete;

    std::string generate(const std::string& model, const std::string& prompt,
                          const std::string& system = "",
                          const std::map<std::string, nlohmann::json>& options = {});

    OllamaResponse chat(const std::string& model, const std::vector<OllamaMsg>& messages,
                         const std::string& system = "",
                         const std::map<std::string, nlohmann::json>& options = {});

    std::pair<std::string, std::string> analyze_support_ticket(const std::string& ticket_text);
    int detect_fraud(const std::string& payment_data_json);
    std::string generate_waf_rule(const std::string& attack_pattern);

private:
    std::string base_url_;
    CURL* curl_;
    std::mutex curl_mtx_;
    std::string request(const std::string& path, const nlohmann::json& body);
};

} // namespace subsys
} // namespace node669427
