package cn.axzo.msg.center.wx.notices.cp;

import cn.axzo.msg.center.wx.notices.compont.WxCpProcessor;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.message.TemplateCardMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企微消息处理器
 *
 * @author cn
 * @version 1.0
 * @description
 * @date 2023/5/25 16:12
 */
@Service
@RequiredArgsConstructor
public class WxCpMessageHandler {
    private final WxCpProcessor wxProcessor;

    public WxCpMessageHandler switchConfig(String corpId, String corpSecret) {
        WxCpDefaultConfigImpl wxMaConfig = new WxCpDefaultConfigImpl();
        wxMaConfig.setCorpId(corpId);
        wxMaConfig.setCorpSecret(corpSecret);
//        wxMaConfig.setAccessToken(token);
        //修改过过期时间为5分钟
//        wxMaConfig.setExpiresTime(System.currentTimeMillis() + 300000);
        wxProcessor.setWxCpConfigStorage(wxMaConfig);
        return this;
    }

    public WxCpMessageSendResult send(WxCpMessage msg) throws WxErrorException {
        return wxProcessor.getMessageService().send(msg);
    }

    public void updateTemplateCardButton(TemplateCardMessage msg) throws WxErrorException {
        wxProcessor.getTaskCardService().updateTemplateCardButton(msg);
    }

    public void updateTemplateCardButton(List<String> userIds, String taskId, String replaceName) throws WxErrorException {
        wxProcessor.getTaskCardService().update(userIds, taskId, replaceName);
    }

    public void updateTemplateCardButton(List<String> userIds, List<Integer> partyIds,
                                         List<Integer> tagIds, Integer atAll, String responseCode,
                                         String replaceName) throws WxErrorException {
        wxProcessor.getTaskCardService().updateTemplateCardButton(userIds, partyIds, tagIds, atAll, responseCode, replaceName);
    }
}
