package com.chenyang.druid.sql.dialect.db2.ast.expr.tablesource;

import com.chenyang.druid.sql.ast.SQLExpr;
import com.chenyang.druid.sql.ast.SQLName;
import com.chenyang.druid.sql.ast.statement.SQLExprTableSource;
import com.chenyang.druid.sql.dialect.db2.ast.DB2SQLObject;
import com.chenyang.druid.sql.dialect.db2.ast.expr.DB2ColumnSimpleDefinitionExpr;
import com.chenyang.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;
import util.sqlparse.visitor.common.Objects;

public class DB2MethodInvokeTableSource extends SQLExprTableSource implements DB2SQLObject, DB2TableSource {
   protected boolean only;
   protected boolean withOrdinality;
   protected boolean isRowsFrom;
   protected List<SQLExpr> parameters = new ArrayList();
   protected List<DB2ColumnSimpleDefinitionExpr> defines = new ArrayList();

   public List<DB2ColumnSimpleDefinitionExpr> getDefines() {
      return this.defines;
   }

   public void setDefines(List<DB2ColumnSimpleDefinitionExpr> defines) {
      this.defines = defines;
      if (defines != null && defines.size() > 0) {
         for(DB2ColumnSimpleDefinitionExpr define : defines) {
            define.setParent(this);
         }
      }

   }

   public List<SQLExpr> getParameters() {
      return this.parameters;
   }

   public void setParameters(List<SQLExpr> parameters) {
      this.parameters = parameters;
   }

   public boolean isOnly() {
      return this.only;
   }

   public void setOnly(boolean only) {
      this.only = only;
   }

   public boolean isWithOrdinality() {
      return this.withOrdinality;
   }

   public void setWithOrdinality(boolean withOrdinality) {
      this.withOrdinality = withOrdinality;
   }

   public boolean equals(Object o) {
      if (this == o) {
         return true;
      } else if (o != null && this.getClass() == o.getClass()) {
         if (!super.equals(o)) {
            return false;
         } else {
            DB2MethodInvokeTableSource that = (DB2MethodInvokeTableSource)o;
            if (that.only != this.only) {
               return false;
            } else if (that.withOrdinality != this.withOrdinality) {
               return false;
            } else {
               return that.isRowsFrom != this.isRowsFrom ? false : Objects.equals(this.parameters, that.parameters);
            }
         }
      } else {
         return false;
      }
   }

   public int hashCode() {
      return Objects.hash(super.hashCode(), this.parameters);
   }

   public void addColumnAlias(SQLName name) {
      if (this.columns == null) {
         this.columns = new ArrayList();
      }

      this.columns.add(name);
   }

   public void addColumnAlias(DB2ColumnSimpleDefinitionExpr define) {
      define.setParent(this);
      this.defines.add(define);
   }

   public boolean isRowsFrom() {
      return this.isRowsFrom;
   }

   public void setRowsFrom(boolean rowsFrom) {
      this.isRowsFrom = rowsFrom;
   }

   protected void accept0(SQLASTVisitor visitor) {
      this.accept0((DB2ASTVisitor)visitor);
   }

   public void accept0(DB2ASTVisitor visitor) {
      if (visitor.visit(this)) {
         if (this.expr != null) {
            this.expr.accept(visitor);
         }

         if (this.parameters != null && this.parameters.size() > 0) {
            for(SQLExpr parameter : this.parameters) {
               parameter.accept(visitor);
            }
         }

         if (this.sampling != null) {
            this.sampling.accept(visitor);
         }
      }

      visitor.endVisit(this);
   }

   public DB2MethodInvokeTableSource clone() {
      DB2MethodInvokeTableSource ts = new DB2MethodInvokeTableSource();
      this.cloneTo(ts);
      if (this.defines != null && this.defines.size() > 0) {
         for(DB2ColumnSimpleDefinitionExpr define : this.defines) {
            ts.defines.add(define.clone());
         }
      }

      ts.isRowsFrom = this.isRowsFrom;
      return ts;
   }
}
