package com.bonus.core.customer.constants;

import cn.hutool.core.date.DateUtil;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

public enum CustAgeEnum {
   ZERO_TEN(0, "0~10", 0, 10),
   TEN_TWENTY(1, "10~20", 10, 20),
   TWENTY_THIRTY(2, "20~30", 20, 30),
   THIRTY_FORTY(3, "30~40", 30, 40),
   FORTY_FIFTY(4, "40~50", 40, 50),
   FIFTY_SIXTY(5, "50~60", 50, 60),
   SIXTY_SEVENTY(6, "60~70", 60, 70),
   SEVENTY_EIGHTY(7, "70~80", 70, 80),
   EIGHTY_NINETY(8, "80~90", 80, 90),
   NINETY_ONE_HUNDRED(9, "90~100", 90, 100),
   ONE_HUNDRED_INTEGER_MAX(10, "大于100", 100, Integer.MAX_VALUE),
   OTHER(11, "其他", (Integer)null, (Integer)null);

   private final Integer key;
   private final String desc;
   private final Integer minAge;
   private final Integer maxAge;

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

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

      return "";
   }

   public static Integer getAge(LocalDate birthDay) {
      return Objects.isNull(birthDay) ? null : DateUtil.ageOfNow(birthDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
   }

   public static CustAgeEnum getEnumByAge(LocalDate birthDay) {
      Integer age = getAge(birthDay);
      if (Objects.isNull(age)) {
         return OTHER;
      } else {
         CustAgeEnum[] var2 = values();
         int var3 = var2.length;

         for(int var4 = 0; var4 < var3; ++var4) {
            CustAgeEnum temp = var2[var4];
            if (age >= temp.getMinAge() && age < temp.getMaxAge()) {
               return temp;
            }
         }

         return OTHER;
      }
   }

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

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

   public Integer getMinAge() {
      return this.minAge;
   }

   public Integer getMaxAge() {
      return this.maxAge;
   }

   private CustAgeEnum(final Integer key, final String desc, final Integer minAge, final Integer maxAge) {
      this.key = key;
      this.desc = desc;
      this.minAge = minAge;
      this.maxAge = maxAge;
   }

   // $FF: synthetic method
   private static CustAgeEnum[] $values() {
      return new CustAgeEnum[]{ZERO_TEN, TEN_TWENTY, TWENTY_THIRTY, THIRTY_FORTY, FORTY_FIFTY, FIFTY_SIXTY, SIXTY_SEVENTY, SEVENTY_EIGHTY, EIGHTY_NINETY, NINETY_ONE_HUNDRED, ONE_HUNDRED_INTEGER_MAX, OTHER};
   }
}
