package com.chenyang.druid.sql.parser;

public enum SQLParserFeature {
   KeepInsertValueClauseOriginalString,
   KeepSelectListOriginalString,
   UseInsertColumnsCache,
   EnableSQLBinaryOpExprGroup,
   OptimizedForParameterized,
   OptimizedForForParameterizedSkipValue,
   KeepComments,
   SkipComments,
   StrictForWall,
   TDDLHint,
   DRDSAsyncDDL,
   DRDSBaseline,
   InsertReader,
   IgnoreNameQuotes,
   KeepNameQuotes,
   SelectItemGenerateAlias,
   PipesAsConcat,
   InsertValueCheckType,
   InsertValueNative,
   EnableCurrentTimeExpr,
   EnableCurrentUserExpr,
   KeepSourceLocation,
   SupportUnicodeCodePoint,
   PrintSQLWhileParsingFailed,
   EnableMultiUnion,
   Spark,
   Presto;

   public final int mask = 1 << this.ordinal();

   public static boolean isEnabled(int features, SQLParserFeature feature) {
      return (features & feature.mask) != 0;
   }

   public static int config(int features, SQLParserFeature feature, boolean state) {
      if (state) {
         features |= feature.mask;
      } else {
         features &= ~feature.mask;
      }

      return features;
   }

   public static int of(SQLParserFeature... features) {
      if (features == null) {
         return 0;
      } else {
         int value = 0;

         for(SQLParserFeature feature : features) {
            value |= feature.mask;
         }

         return value;
      }
   }
}
