package com.bonus.core.marketing.v2.rule.price.constants;

import com.bonus.core.marketing.util.EnumUtil;
import com.bonus.core.marketing.util.ICommonEnum;

import java.util.Objects;

public enum RulePriceEnum implements ICommonEnum {
   RULE_DISCOUNT(1, "打折", "设置某部门某类型的人在某食堂某餐次第一次打折x比例，第二次打折y比例，后续打折z比例"),
   RULE_REDUCTION_TOTAL(2, "累计减免", "设置某部门某类型的人在某食堂某餐次累计减免金额，最多x元"),
   RULE_SUBSIDY_FIXED(3, "固定补贴", "设置某部门某类型的人在某食堂某餐次每笔消费后补贴金额x元"),
   RULE_REDUCTION_FIXED(4, "固定减免", "设置某部门某类型的人在某食堂某餐次第一次最多减免金额x元，第二次最多减免金额y元，后续最多减免金额z元"),
   RULE_DEDUCTION_RATIO(5, "比例扣费", "设置某部门某类型的人在某食堂某餐次每次个人钱包扣费百分之x，补贴钱包扣费百分之y，补贴钱包扣费上限金额z元"),
   RULE_DEDUCTION_FIXED(6, "固定扣费", "设置某部门某类型的人在某食堂某餐次第一次固定扣费x元，第二次固定扣费y元，后续固定扣费z元，并且可额外优惠n元"),
   RULE_DEDUCTION_FULL(7, "满减满折", "设置某部门某类型的人在某食堂某餐次满x元，减y元，（日/月/餐次）可享受几次优惠"),
   RULE_SUM_GIVE(8, "满额赠送", "设置某部门某类型的人在某食堂某餐次累计达到门槛金额赠送x元"),
   RULE_LIMIT_MAX_COUNT(51, "上限次数", "设置某部门某类型的人在某些食堂某些餐次就餐的日、月或者餐次累计上限次数"),
   RULE_LIMIT_MAX_AMOUNT(101, "单笔上限金额", "设置某部门某类型的人在某食堂某餐次单笔使用的单笔上限金额"),
   RULE_LIMIT_SUM_AMOUNT(102, "累计金额", "设置某部门某类型的人在某些食堂某些餐次就餐的日、月或者餐次累计上限金额");

   private final Integer key;
   private final String value;
   private final String desc;

   public static boolean isDiscountRule(Integer key) {
      boolean flag = false;
      RulePriceEnum ruleType = (RulePriceEnum) EnumUtil.getEnumByKey(RulePriceEnum.class, key);
      if (Objects.isNull(ruleType)) {
         return false;
      } else {
         switch (ruleType.ordinal()) {
            case 0:
            case 1:
            case 3:
            case 4:
            case 5:
            case 6:
               flag = true;
            case 2:
            default:
               return flag;
         }
      }
   }

   public static boolean isLimitTimesRule(Integer key) {
      boolean flag = false;
      RulePriceEnum ruleType = (RulePriceEnum)EnumUtil.getEnumByKey(RulePriceEnum.class, key);
      if (Objects.nonNull(ruleType) && ruleType == RULE_LIMIT_MAX_COUNT) {
         flag = true;
      }

      return flag;
   }

   public static boolean isLimitAmountRule(Integer key) {
      boolean flag = false;
      RulePriceEnum ruleType = (RulePriceEnum)EnumUtil.getEnumByKey(RulePriceEnum.class, key);
      if (Objects.isNull(ruleType)) {
         return false;
      } else {
         switch (ruleType.ordinal()) {
            case 9:
            case 10:
               flag = true;
            default:
               return flag;
         }
      }
   }

   public static boolean isGiveRule(Integer key) {
      boolean flag = false;
      RulePriceEnum ruleType = (RulePriceEnum)EnumUtil.getEnumByKey(RulePriceEnum.class, key);
      if (Objects.isNull(ruleType)) {
         return false;
      } else {
         switch (ruleType.ordinal()) {
            case 2:
            case 7:
               flag = true;
            default:
               return flag;
         }
      }
   }

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

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

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

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

   // $FF: synthetic method
   private static RulePriceEnum[] $values() {
      return new RulePriceEnum[]{RULE_DISCOUNT, RULE_REDUCTION_TOTAL, RULE_SUBSIDY_FIXED, RULE_REDUCTION_FIXED, RULE_DEDUCTION_RATIO, RULE_DEDUCTION_FIXED, RULE_DEDUCTION_FULL, RULE_SUM_GIVE, RULE_LIMIT_MAX_COUNT, RULE_LIMIT_MAX_AMOUNT, RULE_LIMIT_SUM_AMOUNT};
   }
}
