class FPlatformEnum {
  constructor(name, index) {
    this.name = name;
    this.index = index;
  }

  static android = new FPlatformEnum('android', 0);
  static iOS = new FPlatformEnum('iOS', 1);
  static web = new FPlatformEnum('web', 2);
  static webOnWin = new FPlatformEnum('webOnWin', 3);
  static webOnMac = new FPlatformEnum('webOnMac', 4);

  static byIndex(index) {
    // 将字符串形式的数字转换为整数类型
    if (typeof index === 'string') {
      index = parseInt(index, 10);
      // 如果转换失败，返回默认值
      if (isNaN(index)) {
        return FPlatformEnum.web;
      }
    }
    switch (index) {
      case 0:
        return FPlatformEnum.android;
      case 1:
        return FPlatformEnum.iOS;
      case 2:
        return FPlatformEnum.web;
      case 3:
        return FPlatformEnum.webOnWin;
      case 4:
        return FPlatformEnum.webOnMac;
      default:
        return FPlatformEnum.web;
    }
  }

  isMobile() {
    return (
      this.index === FPlatformEnum.android.index ||
      this.index === FPlatformEnum.iOS.index
    );
  }

  isPureWeb() {
    return this.index === FPlatformEnum.web.index;
  }

  isShell() {
    return (
      this.index === FPlatformEnum.webOnWin.index ||
      this.index === FPlatformEnum.webOnMac.index
    );
  }

  isWeb() {
    return (
      this.index === FPlatformEnum.web.index ||
      this.index === FPlatformEnum.webOnWin.index ||
      this.index === FPlatformEnum.webOnMac.index
    );
  }
}

export default FPlatformEnum;
