package com.chenyang.druid.sql.dialect.mariadb.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.mariadb.ast.statement.MariadbDeleteStatement;
import com.chenyang.druid.sql.dialect.mariadb.ast.statement.MariadbInsertStatement;
import com.chenyang.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;
   }
}
