package com.alibaba.druid.sql.dialect.gauss.ast.stmt;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLCommentHint;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
import com.alibaba.druid.sql.dialect.gauss.visitor.GaussASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class GaussInsertStatement extends SQLInsertStatement implements GaussSQLStatement {
   private List<ValuesClause> valuesList = new ArrayList();
   private SQLExpr returning;
   private boolean defaultValues = false;
   private List<SQLExpr> onConflictTarget;
   private SQLName onConflictConstraint;
   private SQLExpr onConflictWhere;
   private SQLExpr onConflictUpdateWhere;
   private boolean onConflictDoNothing;
   private List<SQLUpdateSetItem> onConflictUpdateSetItems;
   private final List<SQLExpr> duplicateKeyUpdate = new ArrayList();

   public GaussInsertStatement() {
      this.dbType = DbType.gauss;
   }

   public void cloneTo(GaussInsertStatement x) {
      super.cloneTo(x);

      for(ValuesClause v : this.valuesList) {
         ValuesClause v2 = v.clone();
         v2.setParent(x);
         x.valuesList.add(v2);
      }

      if (this.returning != null) {
         x.setReturning(this.returning.clone());
      }

      x.defaultValues = this.defaultValues;

      for(SQLExpr e : this.duplicateKeyUpdate) {
         SQLExpr e2 = e.clone();
         e2.setParent(x);
         x.duplicateKeyUpdate.add(e2);
      }

   }

   public List<SQLExpr> getDuplicateKeyUpdate() {
      return this.duplicateKeyUpdate;
   }

   public SQLExpr getReturning() {
      return this.returning;
   }

   public void setReturning(SQLExpr returning) {
      this.returning = returning;
   }

   public ValuesClause getValues() {
      return this.valuesList.size() == 0 ? null : (ValuesClause)this.valuesList.get(0);
   }

   public void setValues(ValuesClause values) {
      if (this.valuesList.size() == 0) {
         this.valuesList.add(values);
      } else {
         this.valuesList.set(0, values);
      }

   }

   public List<ValuesClause> getValuesList() {
      return this.valuesList;
   }

   public void addValueCause(ValuesClause valueClause) {
      valueClause.setParent(this);
      this.valuesList.add(valueClause);
   }

   public boolean isDefaultValues() {
      return this.defaultValues;
   }

   public void setDefaultValues(boolean defaultValues) {
      this.defaultValues = defaultValues;
   }

   protected void accept0(SQLASTVisitor visitor) {
      if (visitor instanceof GaussASTVisitor) {
         this.accept0((GaussASTVisitor)visitor);
      } else {
         super.accept0(visitor);
      }

   }

   public void accept0(GaussASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.with);
         this.acceptChild(visitor, this.tableSource);
         this.acceptChild(visitor, this.columns);
         this.acceptChild(visitor, this.valuesList);
         this.acceptChild(visitor, this.query);
         this.acceptChild(visitor, this.returning);
         if (this.duplicateKeyUpdate != null) {
            for(SQLExpr item : this.duplicateKeyUpdate) {
               if (item != null) {
                  item.accept(visitor);
               }
            }
         }
      }

      visitor.endVisit(this);
   }

   public GaussInsertStatement clone() {
      GaussInsertStatement x = new GaussInsertStatement();
      this.cloneTo(x);
      return x;
   }

   public List<SQLExpr> getOnConflictTarget() {
      return this.onConflictTarget;
   }

   public void setOnConflictTarget(List<SQLExpr> onConflictTarget) {
      this.onConflictTarget = onConflictTarget;
   }

   public boolean isOnConflictDoNothing() {
      return this.onConflictDoNothing;
   }

   public void setOnConflictDoNothing(boolean onConflictDoNothing) {
      this.onConflictDoNothing = onConflictDoNothing;
   }

   public List<SQLUpdateSetItem> getOnConflictUpdateSetItems() {
      return this.onConflictUpdateSetItems;
   }

   public void addConflicUpdateItem(SQLUpdateSetItem item) {
      if (this.onConflictUpdateSetItems == null) {
         this.onConflictUpdateSetItems = new ArrayList();
      }

      item.setParent(this);
      this.onConflictUpdateSetItems.add(item);
   }

   public SQLName getOnConflictConstraint() {
      return this.onConflictConstraint;
   }

   public void setOnConflictConstraint(SQLName x) {
      if (x != null) {
         x.setParent(this);
      }

      this.onConflictConstraint = x;
   }

   public SQLExpr getOnConflictWhere() {
      return this.onConflictWhere;
   }

   public void setOnConflictWhere(SQLExpr x) {
      if (x != null) {
         x.setParent(this);
      }

      this.onConflictWhere = x;
   }

   public SQLExpr getOnConflictUpdateWhere() {
      return this.onConflictUpdateWhere;
   }

   public void setOnConflictUpdateWhere(SQLExpr x) {
      if (x != null) {
         x.setParent(this);
      }

      this.onConflictUpdateWhere = x;
   }

   public List<SQLCommentHint> getHeadHintsDirect() {
      return null;
   }
}
