package util.sqlparse.visitor.common.memo;

import com.chenyang.druid.sql.ast.SQLObject;
import java.util.ArrayList;
import java.util.List;
import util.sqlparse.visitor.common.ID;
import util.sqlparse.visitor.common.Objects;
import util.sqlparse.visitor.common.ScopeDialector;
import util.sqlparse.visitor.common.scope.Scope;

public class TableMemo extends ID {
   public String name;
   public String alias;
   public String schema;
   public String nowName;
   public SQLObject ref;
   public Scope scope;
   private String qualifiedName;
   private final List<TableMemo> children;
   public boolean isSub;
   public boolean topTable;
   public TableMemo refTable;
   public String dbLink;
   public boolean sequence;
   public boolean atom;
   public boolean system;

   public TableMemo() {
      this.children = new ArrayList();
   }

   public TableMemo(SQLObject x) {
      this();
      this.ref = x;
   }

   public String getQualifiedName() {
      if (this.qualifiedName == null) {
         this.qualifiedName = this.schema + "." + this.nowName;
      }

      return this.qualifiedName;
   }

   public String getUniqueName() {
      return this.scope.id + ":" + this.getQualifiedName();
   }

   public String getAtomName() {
      return this.schema + "." + this.name;
   }

   public String fullPath(ScopeDialector dialector) {
      return dialector.wrap(this.schema) + "." + dialector.wrap(this.name);
   }

   public List<TableMemo> getChildren() {
      return this.children;
   }

   public String toString() {
      return this.schema + "." + this.name + "." + this.isSub;
   }

   public boolean equals(Object o) {
      if (this == o) {
         return true;
      } else if (o != null && this.getClass() == o.getClass()) {
         TableMemo tableTree = (TableMemo)o;
         return Objects.equals(this.name, tableTree.name) && Objects.equals(this.schema, tableTree.schema) && Objects.equals(this.isSub, tableTree.isSub);
      } else {
         return false;
      }
   }

   public int hashCode() {
      return Objects.hash(this.name, this.schema, this.isSub);
   }
}
