package com.alibaba.druid.sql.dialect.postgresql.ast.stmt.alterTable;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem;
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSQLObjectImpl;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class PGAlterTableSetWith extends PGSQLObjectImpl implements SQLAlterTableItem {
   private boolean withReorgnize = false;
   private DistributeType distributeType;
   private List<PGAlterTableDistributeByOption> options = new ArrayList();

   public boolean isWithReorgnize() {
      return this.withReorgnize;
   }

   public void setWithReorgnize(boolean withReorgnize) {
      this.withReorgnize = withReorgnize;
   }

   public DistributeType getDistributeType() {
      return this.distributeType;
   }

   public void setDistributeType(DistributeType distributeType) {
      this.distributeType = distributeType;
   }

   public List<PGAlterTableDistributeByOption> getOptions() {
      return this.options;
   }

   public void setOptions(List<PGAlterTableDistributeByOption> options) {
      this.options = options;
   }

   public void addOption(PGAlterTableDistributeByOption option) {
      this.options.add(option);
      option.setParent(this);
   }

   public void accept0(PGASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.options);
      }

      visitor.endVisit(this);
   }

   public PGAlterTableSetWith clone() {
      PGAlterTableSetWith c = new PGAlterTableSetWith();
      c.distributeType = this.distributeType;
      c.withReorgnize = this.withReorgnize;
      if (this.options != null && this.options.size() > 0) {
         for(PGAlterTableDistributeByOption option : this.options) {
            c.addOption(option.clone());
         }
      }

      return c;
   }

   public static class PGAlterTableDistributeByOption extends PGSQLObjectImpl {
      private SQLExpr columnName;
      private SQLExpr opClass;

      public SQLExpr getColumnName() {
         return this.columnName;
      }

      public void setColumnName(SQLExpr columnName) {
         columnName.setParent(this);
         this.columnName = columnName;
      }

      public SQLExpr getOpClass() {
         return this.opClass;
      }

      public void setOpClass(SQLExpr opClass) {
         opClass.setParent(this);
         this.opClass = opClass;
      }

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

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

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

         visitor.endVisit(this);
      }

      public PGAlterTableDistributeByOption clone() {
         PGAlterTableDistributeByOption o = new PGAlterTableDistributeByOption();
         o.setColumnName(this.columnName.clone());
         if (this.opClass != null) {
            o.setOpClass(this.opClass.clone());
         }

         return o;
      }
   }

   public static enum DistributeType {
      with,
      by,
      randomly,
      replicated;
   }
}
