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

import cn.hutool.core.collection.ListUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

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

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

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

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

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

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

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

   public static String getAllWalletId() {
      return StringUtils.join(getAllWalletIdList(), ",");
   }

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

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

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