package com.bonus.canteen.core.order.common.vo;

import cn.hutool.core.text.CharSequenceUtil;
import com.bonus.common.houqin.constant.RetCodeEnum;
import com.bonus.canteen.core.pay.api.vo.UnifyPayVO;
import com.bonus.canteen.core.pay.common.constants.PayStateEnum;
import com.bonus.common.houqin.i18n.I18n;

public interface OrderPayResult {
   Integer getCode();

   void setCode(Integer code);

   String getMsg();

   void setMsg(String msg);

   default void fillPayResult(UnifyPayVO payVO, boolean isMobile) {
      if (!PayStateEnum.isPaidState(payVO.getCode()) && !payVO.isAsyncPay() && (!isMobile || !PayStateEnum.isPayingState(payVO.getCode()))) {
         if (PayStateEnum.isFailedState(payVO.getCode()) && payVO.hasUnpaidBalance()) {
            this.setCode(RetCodeEnum.PAY_BALANCE_NO_ENOUGH.getKey());
            this.setMsg(I18n.getMessage("order.buffet.bal-not-enough", new Object[0]));
         } else if (!isMobile && PayStateEnum.isPayingState(payVO.getCode())) {
            this.setCode(RetCodeEnum.PAY_QRCODE_ING.getKey());
            this.setMsg(I18n.getMessage("order.mac.paying", new Object[0]));
         } else {
            this.setCode(RetCodeEnum.FAIL.getKey());
            this.setMsg(CharSequenceUtil.blankToDefault(payVO.getMsg(), I18n.getMessage("order.mac.pay-failed", new Object[0])));
         }
      } else {
         this.setCode(RetCodeEnum.SUCC.getKey());
         this.setMsg(RetCodeEnum.SUCC.getDesc());
      }

   }
}
