package com.chenyang.druid.sql.dialect.mysql.ast.clause;

import com.chenyang.druid.sql.ast.SQLStatement;
import com.chenyang.druid.sql.ast.statement.SQLBlockStatement;
import com.chenyang.druid.sql.ast.statement.SQLIfStatement;
import com.chenyang.druid.sql.ast.statement.SQLLoopStatement;
import com.chenyang.druid.sql.ast.statement.SQLSelectStatement;
import com.chenyang.druid.sql.ast.statement.SQLWhileStatement;
import com.chenyang.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
import com.chenyang.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement;
import com.chenyang.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;

public enum MySqlStatementType {
   SELECT(SQLSelectStatement.class.getName()),
   UPDATE(MySqlUpdateStatement.class.getName()),
   INSERT(MySqlInsertStatement.class.getName()),
   DELETE(MySqlDeleteStatement.class.getName()),
   WHILE(SQLWhileStatement.class.getName()),
   IF(SQLIfStatement.class.getName()),
   LOOP(SQLLoopStatement.class.getName()),
   BLOCK(SQLBlockStatement.class.getName()),
   DECLARE(MySqlDeclareStatement.class.getName()),
   SELECTINTO(MySqlSelectIntoStatement.class.getName()),
   CASE(MySqlCaseStatement.class.getName()),
   UNDEFINED;

   public final String name;

   private MySqlStatementType() {
      this(null);
   }

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

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

      return UNDEFINED;
   }
}
