package com.red.circle.other.inner.enums.user;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 注解类型.
 *
 * @author pengliang on  2019/10/24 14:35
 */
public enum AuthTypeEnum {
  /**
   * 手机.
   */
  MOBILE(0, "手机"),
  /**
   * FACEBOOK.
   */
  FACEBOOK(1, "facebook"),
  /**
   * GOOGLE.
   */
  GOOGLE(2, "google"),

  /**
   * apple.
   */
  APPLE(3, "apple"),

  /**
   * Snapchat.
   */
  SNAPCHAT(4, "snapchat"),

  /**
   * account.
   */
  ACCOUNT(5, "account"),

  /**
   * huawei.
   */
  HUAWEI(6, "huawei"),

  /**
   * imei.
   */
  IMEI(7, "imei");

  private final int value;

  private final String key;

  AuthTypeEnum(int value, String key) {
    this.value = value;
    this.key = key;
  }

  public static String getKey(int value) {
    return Stream.of(AuthTypeEnum.values())
        .filter(authTypeEnum -> Objects.equals(authTypeEnum.getValue(), value))
        .findFirst()
        .map(AuthTypeEnum::getKey)
        .orElse("未知");
  }

  public int getValue() {
    return value;
  }

  public String getKey() {
    return key;
  }

  public static AuthTypeEnum toEnum(String key) {

    try {
      return AuthTypeEnum.valueOf(key);
    } catch (Exception ex) {
      // ignore
    }

    return null;
  }
}
