#ifndef CTAI_CURL_H
#define CTAI_CURL_H

#include <QObject>
#include <QDir>
#include <QFile>
#include <QtConcurrent/QtConcurrent>
#include "curl/curl.h"
#include "curl/easy.h"
#include <QDateTime>
#include "3rdparty/json/json.hpp"
#include "ctai_base.h"
#include <regex>
using json = nlohmann::json;



class ctai_curl : public QObject
{
    Q_OBJECT
public:
    ctai_curl();
    ~ctai_curl();
    void curl_init();
    void send_post_response(model_data,curl_opts);
    void send_stream(model_data &, std::string response_data);
    void send_not_stream(model_data &, std::string response_data);
public:
    std::mutex m_mutex;
private:
    CURL       *m_curl;
    curl_slist *m_headers; 
    CURLcode    m_error;
    model_data  c_data;
    curl_opts   c_opts;
    bool m_initialized; // 添加初始化状态标志
    void set_send_post_option();   
    void set_send_post_opts_reset();
    std::string send_send_body(model_data);
    std::vector<std::string> steam_extract(const std::string &input);
    void set_send_post_headers(std::string head_str);
    void set_curl_ssl(bool);
    void set_curl_timeout(int time);
    void set_curl_followlocation(bool followlocation_state);
    void set_curl_debug_verbose(bool verbose_state);
    void set_curl_tcp_keepalive(bool keepalive_state);
    std::string send_timestamp_to_time(time_t timestamp);
signals:
    void send_post_out_data(model_data out_data);
    void send_post_out_error(std::string);
};

typedef struct call_back_context
{
    ctai_curl *instance;
    model_data m_data;
} call_back_context;

#endif