package com.alibaba.druid.sql.ast.statement;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLReplaceable;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class SQLDropTableGroupStatement extends SQLStatementImpl implements SQLDropStatement, SQLReplaceable {
   protected SQLName name;
   protected boolean ifExists = false;

   public SQLDropTableGroupStatement() {
   }

   public SQLDropTableGroupStatement(DbType dbType) {
      super(dbType);
   }

   protected void accept0(SQLASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.name);
      }

      visitor.endVisit(this);
   }

   public List<SQLObject> getChildren() {
      List<SQLObject> children = new ArrayList();
      if (this.name != null) {
         children.add(this.name);
      }

      return children;
   }

   public SQLName getName() {
      return this.name;
   }

   public void setName(SQLName name) {
      this.name = name;
   }

   public String getTableGroupName() {
      if (this.name == null) {
         return null;
      } else {
         return this.name instanceof SQLName ? this.name.getSimpleName() : null;
      }
   }

   public boolean isIfExists() {
      return this.ifExists;
   }

   public void setIfExists(boolean ifNotExists) {
      this.ifExists = ifNotExists;
   }

   public boolean replace(SQLExpr expr, SQLExpr target) {
      if (this.name == expr) {
         this.setName((SQLName)target);
         return true;
      } else {
         return false;
      }
   }
}
