package com.bonus.common.houqin.mq.tx;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionCheckListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

public interface MQTxCheck<T> extends TransactionCheckListener {
   boolean support(Message message);

   default LocalTransactionState checkLocalTransactionState(MessageExt msg) {
      MQTxState txState = this.check(msg, null);
      if (txState == MQTxState.COMMIT) {
         return LocalTransactionState.COMMIT_MESSAGE;
      } else {
         return txState == MQTxState.ROLLBACK ? LocalTransactionState.ROLLBACK_MESSAGE : LocalTransactionState.UNKNOW;
      }
   }

   MQTxState check(MessageExt message, T payload);
}
