package com.jeequan.jeepay.components.mq.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.components.mq.constant.MQSendTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MchAuditMQ extends AbstractMQ {

    public interface IMQReceiver {
        void receive(MchAuditMQ.MsgPayload payload);
    }

    public static final String MQ_NAME = "QUEUE_MCH_AUDIT";

    /** 内置msg 消息体定义 **/
    private MsgPayload payload;

    /**  【！重要配置项！】 定义Msg消息载体 **/
    @Data
    @AllArgsConstructor
    public static class MsgPayload {

        /** 商户编号 / 进件号 **/
        private String applyId;
    }

    @Override
    public String getMQName() {
        return MQ_NAME;
    }

    @Override
    public MQSendTypeEnum getMQType() {
        return MQSendTypeEnum.QUEUE;
    }

    @Override
    public String toMessage() {
        return JSONObject.toJSONString(payload);
    }

    /** 解析MQ消息， 一般用于接收MQ消息时 **/
    public static MsgPayload parse(String msg){
        return JSON.parseObject(msg, MsgPayload.class);
    }

    public static MchAuditMQ build(String applyId){
        return new MchAuditMQ(new MsgPayload(applyId));
    }
}
