package com.alibaba.druid.sql.ast.expr;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLExprImpl;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLReplaceable;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.Collections;
import java.util.List;

public class SQLFlashbackExpr extends SQLExprImpl implements SQLReplaceable {
   private Type type;
   private SQLExpr expr;

   public SQLFlashbackExpr() {
   }

   public SQLFlashbackExpr(Type type, SQLExpr expr) {
      this.type = type;
      this.setExpr(expr);
   }

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

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

   public SQLExpr getExpr() {
      return this.expr;
   }

   public void setExpr(SQLExpr expr) {
      if (expr != null) {
         expr.setParent(this);
      }

      this.expr = expr;
   }

   public boolean replace(SQLExpr expr, SQLExpr target) {
      if (this.expr == expr) {
         this.setExpr((SQLName)target);
         return true;
      } else {
         return false;
      }
   }

   protected void accept0(SQLASTVisitor visitor) {
      if (visitor.visit(this) && this.expr != null) {
         this.expr.accept(visitor);
      }

      visitor.endVisit(this);
   }

   public List<SQLObject> getChildren() {
      return Collections.singletonList(this.expr);
   }

   public SQLFlashbackExpr clone() {
      SQLFlashbackExpr x = new SQLFlashbackExpr();
      x.type = this.type;
      if (this.expr != null) {
         x.setExpr(this.expr.clone());
      }

      return x;
   }

   public boolean equals(Object o) {
      if (this == o) {
         return true;
      } else if (o != null && this.getClass() == o.getClass()) {
         SQLFlashbackExpr that = (SQLFlashbackExpr)o;
         if (this.type != that.type) {
            return false;
         } else {
            return this.expr != null ? this.expr.equals(that.expr) : that.expr == null;
         }
      } else {
         return false;
      }
   }

   public int hashCode() {
      int result = this.type != null ? this.type.hashCode() : 0;
      result = 31 * result + (this.expr != null ? this.expr.hashCode() : 0);
      return result;
   }

   public static enum Type {
      SCN,
      TIMESTAMP;
   }
}
