#pragma once
#include "common.hpp"
#include <string>
#include <vector>
#include <json/json.h>
#include <curl/curl.h>
#include <map>
#include <mutex>

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();
    std::string generate(const std::string& model, const std::string& prompt,
                          const std::string& system = "",
                          const std::map<std::string, Json::Value>& options = {});
    OllamaResponse chat(const std::string& model, const std::vector<OllamaMsg>& messages,
                         const std::string& system = "",
                         const std::map<std::string, Json::Value>& 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 Json::Value& body);
};
