package com.bonus.canteen.core.account.constants;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum AccWalletTypeEnum {
   WALLET(1, "个人钱包"),
   SUBSIDY(2, "补贴钱包");
   private final Integer key;
   private final String desc;

   // 使用 Map 提升查找效率
   private static final Map<Integer, AccWalletTypeEnum> ENUM_MAP = Arrays.stream(values())
           .collect(Collectors.toMap(AccWalletTypeEnum::getKey, Function.identity()));

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

   public static String getDesc(Integer key) {
      AccWalletTypeEnum enumValue = ENUM_MAP.get(key);
      return enumValue != null ? enumValue.getDesc() : "";
   }

   public static AccWalletTypeEnum getEnum(Integer key) {
      return ENUM_MAP.get(key);
   }

   public static Map<Integer, AccWalletTypeEnum> getEnumMap() {
      return ENUM_MAP;
   }

   public static List<Integer> checkAccCancelWallet() {
      return Arrays.asList(WALLET.getKey(), SUBSIDY.getKey());
   }

   public static String getAllWalletType() {
      return StringUtils.join(getAllWalletTypeList(), ",");
   }

   public static List<Integer> getAllWalletTypeList() {
      return Arrays.stream(values())
              .map(AccWalletTypeEnum::getKey)
              .collect(Collectors.toList());
   }

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

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