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

import com.chenyang.druid.sql.ast.expr.SQLIdentifierExpr;
import com.chenyang.druid.sql.ast.statement.SQLSelectOrderByItem;
import com.chenyang.druid.sql.dialect.oracle.ast.OracleSQLObjectImpl;
import com.chenyang.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class SearchClause extends OracleSQLObjectImpl {
   private Type type;
   private final List<SQLSelectOrderByItem> items = new ArrayList();
   private SQLIdentifierExpr orderingColumn;

   public Type getType() {
      return this.type;
   }

   public void setType(Type type) {
      this.type = type;
   }

   public List<SQLSelectOrderByItem> getItems() {
      return this.items;
   }

   public void addItem(SQLSelectOrderByItem item) {
      if (item != null) {
         item.setParent(this);
      }

      this.items.add(item);
   }

   public SQLIdentifierExpr getOrderingColumn() {
      return this.orderingColumn;
   }

   public void setOrderingColumn(SQLIdentifierExpr orderingColumn) {
      if (orderingColumn != null) {
         orderingColumn.setParent(this);
      }

      this.orderingColumn = orderingColumn;
   }

   public void accept0(OracleASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.items);
         this.acceptChild(visitor, this.orderingColumn);
      }

      visitor.endVisit(this);
   }

   public SearchClause clone() {
      SearchClause x = new SearchClause();
      x.type = this.type;

      for(SQLSelectOrderByItem item : this.items) {
         SQLSelectOrderByItem item2 = item.clone();
         item2.setParent(x);
         x.items.add(item2);
      }

      if (this.orderingColumn != null) {
         x.setOrderingColumn(this.orderingColumn.clone());
      }

      return x;
   }

   public static enum Type {
      DEPTH,
      BREADTH;
   }
}
