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

import com.chenyang.druid.sql.ast.SQLExpr;
import com.chenyang.druid.sql.ast.statement.SQLAlterTableItem;
import com.chenyang.druid.sql.dialect.postgresql.ast.PGSQLObject;
import com.chenyang.druid.sql.dialect.postgresql.ast.PGSQLObjectImpl;
import com.chenyang.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;

public class PGAlterTableAddConstraint extends PGSQLObjectImpl implements SQLAlterTableItem, PGSQLObject {
   private SQLExpr constraint;
   private PGAlterTableAddConstraintUsingIndex usingIndex;

   public SQLExpr getConstraint() {
      return this.constraint;
   }

   public void setConstraint(SQLExpr constraint) {
      this.constraint = constraint;
   }

   public PGAlterTableAddConstraintUsingIndex getUsingIndex() {
      return this.usingIndex;
   }

   public void setUsingIndex(PGAlterTableAddConstraintUsingIndex usingIndex) {
      this.usingIndex = usingIndex;
   }

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

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

      visitor.endVisit(this);
   }

   public PGAlterTableAddConstraint clone() {
      PGAlterTableAddConstraint c = new PGAlterTableAddConstraint();
      if (this.constraint != null) {
         c.setConstraint(this.constraint.clone());
      }

      if (this.usingIndex != null) {
         c.setUsingIndex(this.usingIndex.clone());
      }

      return c;
   }

   public static class PGAlterTableAddConstraintUsingIndex extends PGSQLObjectImpl {
      private SQLExpr constraint;
      private SQLExpr indexName;
      private ConstraintType type;
      private ConstraintStrategy strategy;

      public SQLExpr getConstraint() {
         return this.constraint;
      }

      public void setConstraint(SQLExpr constraint) {
         this.constraint = constraint;
         constraint.setParent(this);
      }

      public SQLExpr getIndexName() {
         return this.indexName;
      }

      public void setIndexName(SQLExpr indexName) {
         this.indexName = indexName;
         indexName.setParent(this);
      }

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

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

      public ConstraintStrategy getStrategy() {
         return this.strategy;
      }

      public void setStrategy(ConstraintStrategy strategy) {
         this.strategy = strategy;
      }

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

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

         visitor.endVisit(this);
      }

      public PGAlterTableAddConstraintUsingIndex clone() {
         PGAlterTableAddConstraintUsingIndex c = new PGAlterTableAddConstraintUsingIndex();
         c.setConstraint(this.constraint);
         c.setIndexName(this.indexName);
         c.strategy = this.strategy;
         c.type = this.type;
         return c;
      }

      public static enum ConstraintType {
         unique,
         primaryKey;
      }

      public static enum ConstraintStrategy {
         deferable,
         notDeferable,
         initiallyDefered,
         initiallyImmediate;
      }
   }
}
