package com.chenyang.druid.sql.dialect.sqlserver.ast.stmt;

import com.chenyang.druid.DbType;
import com.chenyang.druid.sql.ast.SQLExpr;
import com.chenyang.druid.sql.ast.SQLObjectImpl;
import com.chenyang.druid.sql.ast.statement.SQLMergeStatement;
import com.chenyang.druid.sql.ast.statement.SQLWithSubqueryClause;
import com.chenyang.druid.sql.dialect.sqlserver.ast.SQLServerObject;
import com.chenyang.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
import com.chenyang.druid.sql.dialect.sqlserver.ast.SQLServerTop;
import com.chenyang.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;

public class SQLServerMergeStatement extends SQLMergeStatement implements SQLServerObject {
   protected SQLWithSubqueryClause with;
   private SQLServerTop top;
   private ArrayList<SQLObjectImpl> clauses = new ArrayList();
   private SQLServerOutput output;

   public SQLServerMergeStatement() {
      this.dbType = DbType.sqlserver;
   }

   public void accept0(SQLServerASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.with);
         this.acceptChild(visitor, this.top);
         this.acceptChild(visitor, this.getInto());
         this.acceptChild(visitor, this.getUsing());
         this.acceptChild(visitor, this.getOn());
         this.acceptChild(visitor, this.clauses);
         this.acceptChild(visitor, this.output);
      }

      visitor.endVisit(this);
   }

   public void accept0(SQLASTVisitor visitor) {
      this.accept0((SQLServerASTVisitor)visitor);
   }

   public ArrayList<SQLObjectImpl> getClauses() {
      return this.clauses;
   }

   public SQLServerTop getTop() {
      return this.top;
   }

   public void setTop(SQLServerTop top) {
      if (top != null) {
         top.setParent(this);
      }

      this.top = top;
   }

   public SQLWithSubqueryClause getWith() {
      return this.with;
   }

   public void setWith(SQLWithSubqueryClause with) {
      if (with != null) {
         with.setParent(this);
      }

      this.with = with;
   }

   public SQLServerOutput getOutput() {
      return this.output;
   }

   public void setOutput(SQLServerOutput output) {
      if (output != null) {
         output.setParent(this);
      }

      this.output = output;
   }

   public static class MergeDeleteClause extends SQLObjectImpl implements SQLServerObject {
      private SQLExpr where;
      private boolean isBySourse = false;

      protected void accept0(SQLASTVisitor v) {
         this.accept0((SQLServerASTVisitor)v);
      }

      public SQLExpr getWhere() {
         return this.where;
      }

      public void setWhere(SQLExpr where) {
         if (where != null) {
            where.setParent(this);
         }

         this.where = where;
      }

      public void accept0(SQLServerASTVisitor visitor) {
         if (visitor.visit(this)) {
            this.acceptChild(visitor, this.where);
         }

         visitor.endVisit(this);
      }

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

      public void setBySourse(boolean bySourse) {
         this.isBySourse = bySourse;
      }
   }

   public static class SQLServerMergeUpdateClause extends MergeUpdateClause implements SQLServerObject {
      private boolean isBySourse = false;

      public void accept0(SQLASTVisitor v) {
         this.accept0((SQLServerASTVisitor)v);
      }

      public void accept0(SQLServerASTVisitor visitor) {
         if (visitor.visit(this)) {
            this.acceptChild(visitor, this.getItems());
            this.acceptChild(visitor, this.getWhere());
            this.acceptChild(visitor, this.getDeleteWhere());
         }

         visitor.endVisit(this);
      }

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

      public void setBySourse(boolean bySourse) {
         this.isBySourse = bySourse;
      }
   }

   public static class SQLServerMergeInsertClause extends MergeInsertClause implements SQLServerObject {
      private boolean isByTarget = false;
      private boolean defaultValues = false;

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

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

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

      public void setByTarget(boolean byTarget) {
         this.isByTarget = byTarget;
      }

      public void accept0(SQLASTVisitor v) {
         this.accept0((SQLServerASTVisitor)v);
      }

      public void accept0(SQLServerASTVisitor visitor) {
         if (visitor.visit(this)) {
            this.acceptChild(visitor, this.getColumns());
            this.acceptChild(visitor, this.getValues());
            this.acceptChild(visitor, this.getWhere());
         }

         visitor.endVisit(this);
      }
   }
}
