package cn.axzo.workflow.server.mq.outside.consumer;

import cn.axzo.framework.rocketmq.Event;
import cn.axzo.framework.rocketmq.EventConsumer;
import cn.axzo.framework.rocketmq.EventHandler;
//import cn.axzo.riven.client.common.enums.DingtalkEventEnum;
//import cn.axzo.riven.client.model.DingtalkReceiveMqModel;
//import cn.axzo.riven.client.model.DingtalkSendMqModel;
//import cn.axzo.riven.client.model.SampleText;
import cn.axzo.workflow.server.mq.outside.producer.DingtalkSendProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 监听钉钉群消息的事件
 *
 * @author wangli
 * @since 2024-10-25 11:16
 */
@Slf4j
@Component
public class DingtalkReceiveListener implements EventHandler, InitializingBean {
    @Value("${spring.application.name}")
    private String applicationName;
    @Resource
    private EventConsumer eventConsumer;
    @Resource
    private DingtalkSendProducer dingtalkSendProducer;

    @Override
    public void onEvent(Event event, EventConsumer.Context context) {

    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }

//    @Override
//    public void onEvent(Event event, EventConsumer.Context context) {
//        log.info("receive dingding message: {}", event.getTargetId());
//
//        if (!Objects.equals(applicationName, event.getTargetType())) {
//            return;
//        }
//        DingtalkReceiveMqModel data = event.normalizedData(DingtalkReceiveMqModel.class);
//        if (log.isDebugEnabled()) {
//            log.debug("message data: {}", JSON.toJSONString(data));
//        }
//
//        DingtalkSendMqModel<SampleText> sendModel = new DingtalkSendMqModel<>();
//        sendModel.setTraceId(data.getTraceId());
//        sendModel.setConversationId(data.getConversationId());
//        sendModel.setMsgId(data.getMsgId());
//        sendModel.setRobotCode(data.getRobotCode());
//        sendModel.setMessage(SampleText.from("由 WorkflowEngine 处理的消息: " + data.getContent()));
//
//        dingtalkSendProducer.send(sendModel);
//    }

//    @Override
//    public void afterPropertiesSet() throws Exception {
//        eventConsumer.registerHandler(DingtalkEventEnum.receive.getEventCode(), this);
//    }
}
