package com.bonus.core.order.common.constants;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bonus.core.pay.common.constants.PayStateEnum;

import java.util.Objects;

public enum OrderStateMixMobileEnum implements Converter<Integer> {
   PAID(1, "已支付"),
   MAKING(3, "制作中"),
   WAIT_DELIVERY(5, "待配送"),
   DELIVERING(7, "配送中"),
   WAIT_TAKE(8, "待取餐"),
   CANCEL(9, "已取消"),
   REFUND(10, "已退单"),
   COMPLETE(11, "已完成"),
   PLACED(21, "已下单"),
   UN_PAY(22, "未支付"),
   PART_PAY(23, "部分支付"),
   PAY_FAILED(24, "支付失败"),
   PART_REFUND(25, "部分退单"),
   PAYING(26, "支付中");

   private final Integer key;
   private final String desc;

   private OrderStateMixMobileEnum(Integer key, String desc) {
      this.key = key;
      this.desc = desc;
   }

   @Override
   public Class<?> supportJavaTypeKey() {
      return String.class;
   }

   @Override
   public CellDataTypeEnum supportExcelTypeKey() {
      return null;
   }

   @Override
   public WriteCellData<OrderStateEnum> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
      return Objects.isNull(value) ? new WriteCellData("") : new WriteCellData(getDesc(value));
   }

   public static String getDesc(Integer key) {
      OrderStateMixMobileEnum[] var1 = values();
      int var2 = var1.length;

      for(int var3 = 0; var3 < var2; ++var3) {
         OrderStateMixMobileEnum temp = var1[var3];
         if (temp.getKey().equals(key)) {
            return temp.getDesc();
         }
      }

      return "";
   }

   public static Integer mixStateBy(Integer orderState, Integer payState, Integer orderRefundState, Integer dishesState) {
      if (OrderRefundStateEnum.FINISH.getKey().equals(orderRefundState)) {
         return REFUND.getKey();
      } else if (OrderStateEnum.CANCEL.getKey().equals(orderState)) {
         return CANCEL.getKey();
      } else if (PayStateEnum.isFailedState(payState)) {
         return PAY_FAILED.getKey();
      } else if (PayStateEnum.isPayingState(payState)) {
         return PAYING.getKey();
      } else if (PayStateEnum.isUnPayState(payState)) {
         return UN_PAY.getKey();
      } else if (OrderStateEnum.FINISH.getKey().equals(orderState)) {
         return COMPLETE.getKey();
      } else if (DishesStateEnum.WAIT_TAKE.getKey().equals(dishesState)) {
         return WAIT_TAKE.getKey();
      } else if (DishesStateEnum.DELIVERING.getKey().equals(dishesState)) {
         return DELIVERING.getKey();
      } else if (DishesStateEnum.WAIT_DELIVERY.getKey().equals(dishesState)) {
         return WAIT_DELIVERY.getKey();
      } else if (DishesStateEnum.MAKING.getKey().equals(dishesState)) {
         return MAKING.getKey();
      } else if (OrderRefundStateEnum.PART_SUCC.getKey().equals(orderRefundState)) {
         return PART_REFUND.getKey();
      } else if (PayStateEnum.PAY_SUCC.getKey().equals(payState)) {
         return PAID.getKey();
      } else {
         return PayStateEnum.PART_PAY.getKey().equals(payState) ? PART_PAY.getKey() : PLACED.getKey();
      }
   }

   public Integer getKey() {
      return this.key;
   }

   public String getDesc() {
      return this.desc;
   }

}
