package com.yutou.napcat.handle;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.okhttp.BaseBean;
import com.yutou.qqbot.utlis.StringUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

public class MessageHandleBuild {
    private List<BaseHandle<?>> msgList = new ArrayList<>();
    private long qq;
    private boolean autoEscape;
    private boolean isGroup;
    private String messageId;

    public static MessageHandleBuild create() {
        return new MessageHandleBuild();
    }

    private MessageHandleBuild() {
        msgList = new ArrayList<>();
    }

    public MessageHandleBuild setQQNumber(long qq) {
        this.qq = qq;
        return this;
    }

    public MessageHandleBuild setAutoEscape(boolean autoEscape) {
        this.autoEscape = autoEscape;
        return this;
    }

    public MessageHandleBuild add(BaseHandle<?> msg) {
        msgList.add(msg);
        return this;
    }

    public MessageHandleBuild setGroup(boolean group) {
        isGroup = group;
        return this;
    }
    public MessageHandleBuild setMessageId(String messageId) {
        this.messageId = messageId;
        return this;
    }
    public JSONObject build() {
        JSONObject json=new JSONObject();
        if(isGroup){
            json.put("group_id", qq);
        }else {
            json.put("user_id", qq);
        }
        json.put("auto_escape", autoEscape);
        json.put("message", msgList);
        if(!StringUtils.isEmpty(messageId)){
            json.put("message_id",messageId);
        }
        return json;
    }
}
