package com.red.circle.common.business.enums;

import java.util.Arrays;
import java.util.Objects;

/**
 * SVIP.
 *
 * @author pengshigang on 2022/8/19
 */
public enum SVIPLevelEnum {

  /**
   * 不是SVIP.
   */
  NONE(0),

  /**
   * SVIP1.
   */
  SVIP_1(1),

  /**
   * SVIP2.
   */
  SVIP_2(2),

  /**
   * SVIP3.
   */
  SVIP_3(3),

  /**
   * SVIP4.
   */
  SVIP_4(4),

  /**
   * SVIP5.
   */
  SVIP_5(5)
  ;

  private final Integer level;

  SVIPLevelEnum(Integer level) {
    this.level = level;
  }

  public static SVIPLevelEnum getByLevel(Integer inputLevel) {

    return Arrays.stream(SVIPLevelEnum.values())
        .filter(levelEnum -> Objects.equals(levelEnum.getLevel(), inputLevel))
        .findAny()
        .orElse(NONE);
  }

  public Integer getLevel() {
    return level;
  }

  public static SVIPLevelEnum toEnum(String key) {
    try {
      return SVIPLevelEnum.valueOf(key);
    } catch (Exception ex) {
      // ignore
    }
    return null;
  }

}
