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 MchAuditThirdNotifyMQ extends AbstractMQ {

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

    public static final String MQ_NAME = "QUEUE_MCH_THIRD_AUDIT_NOTIFY";

    public static final int TYPE_AUDIT = 1;

    public static final int TYPE_AUDIT_MODIFY = 2;

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

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

        private String applyId;

        /**
         * 1、进件；2、商户信息变更
         */
        private int type;
    }

    @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);
    }

    /**  【！重要配置项！】 构造MQModel , 一般用于发送MQ时 **/
    public static MchAuditThirdNotifyMQ build(String applyId, int type){
        return new MchAuditThirdNotifyMQ(new MchAuditThirdNotifyMQ.MsgPayload(applyId, type));
    }

    public static MchAuditThirdNotifyMQ build(String notifyData){
        return new MchAuditThirdNotifyMQ(parse(notifyData));
    }
}
