package com.alibaba.druid.sql.ast;

import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class SQLIndexOptions extends SQLObjectImpl {
   private String indexType;
   private SQLExpr keyBlockSize;
   private String parserName;
   private SQLExpr comment;
   private String algorithm;
   private String lock;
   protected boolean visible = false;
   protected boolean invisible = false;
   private List<SQLAssignItem> otherOptions = new ArrayList();

   public String getIndexType() {
      return this.indexType;
   }

   public void setIndexType(String indexType) {
      this.indexType = indexType;
   }

   public SQLExpr getKeyBlockSize() {
      return this.keyBlockSize;
   }

   public void setKeyBlockSize(SQLExpr keyBlockSize) {
      if (keyBlockSize != null) {
         if (this.getParent() != null && this.getParent().getParent() != null) {
            keyBlockSize.setParent(this.getParent().getParent());
         } else {
            keyBlockSize.setParent(this);
         }
      }

      this.keyBlockSize = keyBlockSize;
      if (keyBlockSize != null && this.getParent() != null && this.getParent() instanceof SQLIndexDefinition) {
         SQLIndexDefinition parent = (SQLIndexDefinition)this.getParent();
         SQLAssignItem assignItem = new SQLAssignItem(new SQLIdentifierExpr("KEY_BLOCK_SIZE"), keyBlockSize);
         if (this.getParent() != null && this.getParent().getParent() != null) {
            assignItem.setParent(this.getParent().getParent());
         } else {
            assignItem.setParent(this);
         }

         parent.getCompatibleOptions().add(assignItem);
      }

   }

   public String getParserName() {
      return this.parserName;
   }

   public void setParserName(String parserName) {
      this.parserName = parserName;
   }

   public SQLExpr getComment() {
      return this.comment;
   }

   public void setComment(SQLExpr comment) {
      if (comment != null) {
         if (this.getParent() != null && this.getParent().getParent() != null) {
            comment.setParent(this.getParent().getParent());
         } else {
            comment.setParent(this);
         }
      }

      this.comment = comment;
   }

   public String getAlgorithm() {
      return this.algorithm;
   }

   public void setAlgorithm(String algorithm) {
      this.algorithm = algorithm;
      if (algorithm != null && this.getParent() != null && this.getParent() instanceof SQLIndexDefinition) {
         SQLIndexDefinition parent = (SQLIndexDefinition)this.getParent();
         SQLAssignItem assignItem = new SQLAssignItem(new SQLIdentifierExpr("ALGORITHM"), new SQLIdentifierExpr(algorithm));
         if (this.getParent() != null && this.getParent().getParent() != null) {
            assignItem.setParent(this.getParent().getParent());
         } else {
            assignItem.setParent(this);
         }

         parent.getCompatibleOptions().add(assignItem);
      }

   }

   public String getLock() {
      return this.lock;
   }

   public void setLock(String lock) {
      this.lock = lock;
      if (lock != null && this.getParent() != null && this.getParent() instanceof SQLIndexDefinition) {
         SQLIndexDefinition parent = (SQLIndexDefinition)this.getParent();
         SQLAssignItem assignItem = new SQLAssignItem(new SQLIdentifierExpr("LOCK"), new SQLIdentifierExpr(lock));
         if (this.getParent() != null && this.getParent().getParent() != null) {
            assignItem.setParent(this.getParent().getParent());
         } else {
            assignItem.setParent(this);
         }

         parent.getCompatibleOptions().add(assignItem);
      }

   }

   public List<SQLAssignItem> getOtherOptions() {
      return this.otherOptions;
   }

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

   public void cloneTo(SQLIndexOptions options) {
      SQLObject parent;
      if (options.getParent() != null && options.getParent().getParent() != null) {
         parent = options.getParent().getParent();
      } else {
         parent = options;
      }

      options.indexType = this.indexType;
      if (this.keyBlockSize != null) {
         options.keyBlockSize = this.keyBlockSize.clone();
         options.keyBlockSize.setParent(parent);
      }

      options.parserName = this.parserName;
      if (this.comment != null) {
         options.comment = this.comment.clone();
         options.comment.setParent(parent);
      }

      options.algorithm = this.algorithm;
      options.lock = this.lock;

      for(SQLAssignItem item : this.otherOptions) {
         SQLAssignItem item1 = item.clone();
         item1.setParent(parent);
         options.otherOptions.add(item1);
      }

   }

   public boolean isInvisible() {
      return this.invisible;
   }

   public void setInvisible(boolean invisible) {
      this.invisible = invisible;
   }

   public boolean isVisible() {
      return this.visible;
   }

   public void setVisible(boolean visible) {
      this.visible = visible;
   }
}
