package com.chenyang.druid.sql.dialect.mariadb.ast.statement;

import com.chenyang.druid.sql.ast.SQLExpr;
import com.chenyang.druid.sql.ast.SQLName;
import com.chenyang.druid.sql.ast.expr.SQLIdentifierExpr;
import com.chenyang.druid.sql.ast.expr.SQLTextLiteralExpr;
import com.chenyang.druid.sql.ast.expr.SQLValuableExpr;
import com.chenyang.druid.sql.ast.statement.SQLAssignItem;
import com.chenyang.druid.sql.dialect.mariadb.visitor.MariadbASTVisitor;
import com.chenyang.druid.util.FnvHash;
import java.util.ArrayList;
import java.util.List;

public class MariadbCreateFullTextCharFilterStatement extends MariadbStatementImpl {
   private SQLName name;
   private SQLTextLiteralExpr typeName;
   protected final List<SQLAssignItem> options = new ArrayList();

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

      visitor.endVisit(this);
   }

   public SQLName getName() {
      return this.name;
   }

   public void setName(SQLName name) {
      if (name != null) {
         name.setParent(this);
      }

      this.name = name;
   }

   public SQLTextLiteralExpr getTypeName() {
      return this.typeName;
   }

   public void setTypeName(SQLTextLiteralExpr typeName) {
      if (this.name != null) {
         this.name.setParent(this);
      }

      this.typeName = typeName;
   }

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

   public void addOption(String name, SQLExpr value) {
      SQLAssignItem assignItem = new SQLAssignItem(new SQLIdentifierExpr(name), value);
      assignItem.setParent(this);
      this.options.add(assignItem);
   }

   public SQLExpr getOption(String name) {
      if (name == null) {
         return null;
      } else {
         long hash64 = FnvHash.hashCode64(name);

         for(SQLAssignItem item : this.options) {
            SQLExpr target = item.getTarget();
            if (target instanceof SQLIdentifierExpr && ((SQLIdentifierExpr)target).hashCode64() == hash64) {
               return item.getValue();
            }
         }

         return null;
      }
   }

   public Object getOptionValue(String name) {
      SQLExpr option = this.getOption(name);
      return option instanceof SQLValuableExpr ? ((SQLValuableExpr)option).getValue() : null;
   }
}
