package com.bonus.canteen.core.marketing.v2.constants;

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.marketing.util.EnumUtil;
import com.bonus.canteen.core.marketing.util.ICommonEnum;
import com.bonus.canteen.core.marketing.v2.rule.price.constants.RulePriceEnum;
import com.bonus.canteen.core.order.common.constants.OrderTypeEnum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum MarketSceneTypeEnum implements ICommonEnum {
   SCENE_DEFAULT(1, "食堂", (List)null, "包括：当餐点餐、预定餐、报餐、包间、餐桌、线下消费、补扣、外部订单"),
   SCENE_BUFFET(10, "自助餐", CollUtil.newArrayList(new Integer[]{RulePriceEnum.RULE_DISCOUNT.getKey(), RulePriceEnum.RULE_DEDUCTION_RATIO.getKey(), RulePriceEnum.RULE_REDUCTION_TOTAL.getKey(), RulePriceEnum.RULE_SUM_GIVE.getKey()}), "包括：自助餐"),
   SCENE_SUPERMARKET(20, "商超", (List)null, "包括：商城、预定商城"),
   SCENE_BUS(30, "班车", CollUtil.newArrayList(new Integer[]{RulePriceEnum.RULE_DEDUCTION_FIXED.getKey()}), "包括：班车");

   private Integer key;
   private String value;
   private List<Integer> enableRule;
   private String desc;

   public static MarketSceneTypeEnum getSceneTypeByOrderType(Integer orderType) {
      OrderTypeEnum orderTypeEnum = OrderTypeEnum.getEnumByKey(orderType);
      MarketSceneTypeEnum sceneTypeEnum;
      switch (orderTypeEnum) {
         case BUFFET:
            sceneTypeEnum = SCENE_BUFFET;
            break;
         case SHOP:
         case RESERVE_SHOP:
            sceneTypeEnum = SCENE_SUPERMARKET;
            break;
         case BUS:
            sceneTypeEnum = SCENE_BUS;
            break;
         default:
            sceneTypeEnum = SCENE_DEFAULT;
      }

      return sceneTypeEnum;
   }

   public static List<Integer> getOrderTypeBySceneType(Integer sceneType) {
      List<Integer> orderTypes = new ArrayList();
      MarketSceneTypeEnum sceneTypeEnum = (MarketSceneTypeEnum) EnumUtil.getEnumByKey(MarketSceneTypeEnum.class, sceneType);
      switch (sceneTypeEnum.ordinal()) {
         case 1:
            ((List)orderTypes).add(OrderTypeEnum.BUFFET.getKey());
            break;
         case 2:
            ((List)orderTypes).add(OrderTypeEnum.SHOP.getKey());
            ((List)orderTypes).add(OrderTypeEnum.RESERVE_SHOP.getKey());
            break;
         case 3:
            ((List)orderTypes).add(OrderTypeEnum.BUS.getKey());
            break;
         default:
            orderTypes = (List)Arrays.stream(OrderTypeEnum.values()).map(OrderTypeEnum::getKey).filter((e) -> {
               return OrderTypeEnum.isCanteenCategory(e) && !OrderTypeEnum.BUFFET.getKey().equals(e);
            }).collect(Collectors.toList());
      }

      return (List)orderTypes;
   }

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

   @Override
   public String getValue() {
      return this.value;
   }

   @Override
   public List<Integer> getEnableRule() {
      return this.enableRule;
   }

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

   private MarketSceneTypeEnum(final Integer key, final String value, final List enableRule, final String desc) {
      this.key = key;
      this.value = value;
      this.enableRule = enableRule;
      this.desc = desc;
   }

   // $FF: synthetic method
   private static MarketSceneTypeEnum[] $values() {
      return new MarketSceneTypeEnum[]{SCENE_DEFAULT, SCENE_BUFFET, SCENE_SUPERMARKET, SCENE_BUS};
   }
}
