package com.yutou.nas.utils;

import com.alibaba.fastjson2.JSONObject;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class QQBotManager {


    private static QQBotManager botManager = null;


    private QQBotManager() {
        Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
        if (isRun != null && (boolean) isRun) {
        }
    }



    public static QQBotManager getInstance() {
        if (botManager == null) {
            botManager = new QQBotManager();
        }
        return botManager;
    }



    public String sendMessage(String text) {
        JSONObject json = new JSONObject();
        json.put("qq", 891655174);
        json.put("message",text);
        Map<String, String> header = new HashMap<>();
        header.put("content-type", "application/json");
        return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
    }

    public String sendMessage(long qq,String text) {
        JSONObject json = new JSONObject();
        json.put("qq", qq);
        json.put("message",text);
        Map<String, String> header = new HashMap<>();
        header.put("content-type", "application/json");
        return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
    }

    public String sendMessage(String imageUrl, String message) {
        return sendMessage(891655174,imageUrl,message);
    }
    public String sendMessage(long qq,String imageUrl, String message) {
        JSONObject json = new JSONObject();
        json.put("qq", qq);
        json.put("message",message);
        json.put("image", imageUrl);
        Map<String, String> header = new HashMap<>();
        header.put("content-type", "application/json");
        return HttpTools.http_post("http://"+ConfigTools.load(ConfigTools.CONFIG,"nas_ip",String.class)+"/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
    }


    public static void main(String[] args) {
        getInstance();
    }
}
