package com.bonus.canteen.core.order.mq.utils;

import cn.hutool.core.lang.UUID;
import com.bonus.canteen.core.common.utils.MqUtil;
import com.bonus.canteen.core.order.mq.bo.OrderCancelBO;
import com.bonus.common.houqin.constant.GlobalConstants;
import com.bonus.common.houqin.mq.constant.LeMqConstant;
import com.bonus.common.houqin.utils.JacksonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

public class OrderMQUtils {
   private static final Logger log = LoggerFactory.getLogger(OrderMQUtils.class);
   public static LocalDateTime orderTimeoutByOrderId(Long orderId, int delaySecond) {
      log.info("[订单MQ]发送未支付订单异步支付超时通知, 订单ID: {}", orderId);
      try {
         OrderCancelBO orderCancelPO = new OrderCancelBO();
         orderCancelPO.setOrderId(orderId);
         orderCancelPO.setMerchantId(GlobalConstants.TENANT_ID);
         orderCancelPO.setTraceId(UUID.fastUUID().toString());
         MqUtil.sendDelay(JacksonUtil.writeValueAsString(orderCancelPO), LeMqConstant.Topic.ORDER_V3_ASYNC_TIMEOUT, delaySecond * 1000);
      }catch (Exception ex) {
         log.error("[订单MQ]发送未支付订单超时通知失败, 订单ID: {}", orderId, ex);
      }
      return LocalDateTime.now().plusSeconds(delaySecond);
   }
}
