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.NoArgsConstructor;

/**
 * TODO
 *
 * @author crystal
 * @date 2024/1/29 16:11
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PayOrderMarketMQ extends AbstractMQ{

    /**
     * 红包
     */
    public static final byte RED_TYPE = 1;

    /**
     * 提现手续费
     */
    public static final byte CASH_FEE_TYPE = 2;

    /** 【！重要配置项！】 定义MQ名称 **/
    public static final String MQ_NAME = "QUEUE_PAY_ORDER_MARKET";

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

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

        private Byte type;
    }

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

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

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


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

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

    /** 定义 IMQReceiver 接口： 项目实现该接口则可接收到对应的业务消息  **/
    public interface IMQReceiver{
        void receive(PayOrderMarketMQ.MsgPayload payload);
    }
}
