package com.alibaba.druid.sql.dialect.mariadb.ast.clause;

import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLBlockStatement;
import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
import com.alibaba.druid.sql.ast.statement.SQLLoopStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLWhileStatement;
import com.alibaba.druid.sql.dialect.mariadb.ast.statement.MariadbDeleteStatement;
import com.alibaba.druid.sql.dialect.mariadb.ast.statement.MariadbInsertStatement;
import com.alibaba.druid.sql.dialect.mariadb.ast.statement.MariadbUpdateStatement;

public enum MariadbStatementType {
   SELECT(SQLSelectStatement.class.getName()),
   UPDATE(MariadbUpdateStatement.class.getName()),
   INSERT(MariadbInsertStatement.class.getName()),
   DELETE(MariadbDeleteStatement.class.getName()),
   WHILE(SQLWhileStatement.class.getName()),
   IF(SQLIfStatement.class.getName()),
   LOOP(SQLLoopStatement.class.getName()),
   BLOCK(SQLBlockStatement.class.getName()),
   DECLARE(MariadbDeclareStatement.class.getName()),
   SELECTINTO(MariadbSelectIntoStatement.class.getName()),
   CASE(MariadbCaseStatement.class.getName()),
   UNDEFINED;

   public final String name;

   private MariadbStatementType() {
      this(null);
   }

   private MariadbStatementType(String name) {
      this.name = name;
   }

   public static MariadbStatementType getType(SQLStatement stmt) {
      for(MariadbStatementType type : values()) {
         if (type.name == stmt.getClass().getName()) {
            return type;
         }
      }

      return UNDEFINED;
   }
}
