package de.dhbwstuttgart.syntaxtree;

import java.io.File;
import java.util.*;

import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.typeinference.result.ResultSet;
//import sun.security.x509.X509CertInfo;

public class SourceFile extends SyntaxTreeNode {
  private String pkgName;

  public final List<ClassOrInterface> KlassenVektor;
  public final Set<JavaClassName> imports;

  private boolean isGenerated;

  public List<ClassOrInterface> availableClasses = new ArrayList<>();
  public List<ASTToTargetAST.Generics> generics = new ArrayList<>();

  /**
   * Die SourceFile reprÃ¤sntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
   * SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
   */
  public SourceFile(String pkgName, List<ClassOrInterface> classDefinitions, Set<JavaClassName> imports) {
    super(new NullToken());
    //if (classDefinitions.size() > 0) { // Enthält die Liste Klassen?
      this.KlassenVektor = classDefinitions; // Klassen werden übernommen
    //} else {
    //  this.KlassenVektor = null; // es handelt sich um ein "Java Module"
    //}
    this.pkgName = pkgName;
    this.imports = imports;
  }

  public SourceFile(SourceFile sf) {
    super(new NullToken());
    this.KlassenVektor = new ArrayList<>(sf.KlassenVektor);
    this.imports = new HashSet<>(sf.imports);
  }

  public void addResultSet(ResultSet rs) {

  }

  public void setPackageName(String packageName) {
    this.pkgName = packageName;
  }

  public void setGenerated() {
    this.isGenerated = true;
  }

  public boolean isGenerated() {
    return this.isGenerated;
  }

  public String getPkgName() {
    return this.pkgName;
  }

  // Get imports (to test implementation)
  public Set<JavaClassName> getImports() {
    return this.imports;
  }

  public List<ClassOrInterface> getClasses() {
    return KlassenVektor;
  }

  public List<Method> getAllMethods() {
    List<Method> ret = new ArrayList<>();
    getClasses().forEach(cl -> ret.addAll(cl.getMethods()));
    return ret;
  }

  @Override
  public void accept(ASTVisitor visitor) {
    visitor.visit(this);
  }
}
