package com.justeat.mickeydb;

import com.google.common.base.Objects;
import com.justeat.mickeydb.MickeyDatabaseModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.xbase.lib.Functions.Function1;

@SuppressWarnings("all")
public class ModelUtil {
  /**
   * def static <T extends DDLStatement> ArrayList<T> findPreviousStatementsOfType(DDLStatement stmt, Class<T> statementType, boolean inclusive) {
   * var list = new ArrayList<T>()
   * 
   * var db = ModelUtil::getAncestorOfType(stmt, typeof(DatabaseBlock))
   * 
   * for(MigrationBlock migration : db.migrations) {
   * for(ddl : migration.statements) {
   * 
   * if(!inclusive) {
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * 
   * if(statementType.isAssignableFrom(ddl.getClass())) {
   * list.add(ddl as T)
   * }
   * 
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * }
   * 
   * if(ModelUtil::getAncestorOfType(stmt, typeof(InitBlock)) != null) {
   * for(ddl : db.init.statements) {
   * 
   * if(!inclusive) {
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * 
   * if(statementType.isAssignableFrom(ddl.getClass())) {
   * list.add(ddl as T)
   * }
   * 
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * }
   * 
   * return list
   * }
   * 
   * def static <T extends DDLStatement> ArrayList<T> findPreviousStatementsOfType(DatabaseBlock db, DDLStatement stmt, Class<T> statementType, boolean inclusive) {
   * var list = new ArrayList<T>()
   * 
   * for(MigrationBlock migration : db.migrations) {
   * for(ddl : migration.statements) {
   * 
   * if(!inclusive) {
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * 
   * if(statementType.isAssignableFrom(ddl.getClass())) {
   * list.add(ddl as T)
   * }
   * 
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * }
   * 
   * if(db.init != null) {
   * for(ddl : db.init.statements) {
   * 
   * if(!inclusive) {
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * 
   * if(statementType.isAssignableFrom(ddl.getClass())) {
   * list.add(ddl as T)
   * }
   * 
   * if(ddl == stmt) {
   * return list
   * }
   * }
   * }
   * 
   * return list
   * }
   */
  public static <T extends EObject> T getAncestorOfType(final EObject obj, final Class<T> ancestorType) {
    EObject temp = obj;
    while ((!Objects.equal(temp.eContainer(), null))) {
      {
        EObject _eContainer = temp.eContainer();
        temp = _eContainer;
        Class<? extends EObject> _class = temp.getClass();
        boolean _isAssignableFrom = ancestorType.isAssignableFrom(_class);
        if (_isAssignableFrom) {
          return ((T) temp);
        }
      }
    }
    return null;
  }
  
  /**
   * walks back and visits each previous statement from the given statement, returning
   * false will cancel the process
   */
  public static void forEachPreviousStatement(final /* DDLStatement */Object stmt, final /* Function1<DDLStatement, Boolean> */Object delegate) {
    throw new Error("Unresolved compilation problems:"
      + "\nMigrationBlock cannot be resolved to a type."
      + "\nDDLStatement cannot be resolved to a type."
      + "\nMigrationBlock cannot be resolved to a type."
      + "\nMigrationBlock cannot be resolved to a type."
      + "\nDDLStatement cannot be resolved to a type."
      + "\n!= cannot be resolved"
      + "\nstatements cannot be resolved"
      + "\nlast cannot be resolved");
  }
  
  public static ArrayList<EObject> getAllReferenceableSingleSources(final /* SelectCoreExpression */Object expr) {
    throw new Error("Unresolved compilation problems:"
      + "\nSelectCore cannot be resolved to a type."
      + "\nSelectExpression cannot be resolved to a type."
      + "\nUnreachable code: The if condition can never match. It is already handled by a previous condition."
      + "\nThe method getAllReferenceableSingleSources(SelectCoreExpression) from the type ModelUtil refers to the missing type SelectCoreExpression"
      + "\nThe method getAllReferenceableSingleSources(SelectCoreExpression) from the type ModelUtil refers to the missing type SelectCoreExpression"
      + "\nThe method findAllSingleSources(SelectExpression) from the type ModelUtil refers to the missing type SingleSource"
      + "\nleft cannot be resolved"
      + "\nright cannot be resolved");
  }
  
  public static /* ArrayList<SingleSource> */Object findAllSingleSources(final /* SelectExpression */Object expr) {
    throw new Error("Unresolved compilation problems:"
      + "\nSingleSource cannot be resolved to a type."
      + "\nsource cannot be resolved"
      + "\nsource cannot be resolved"
      + "\nsource cannot be resolved"
      + "\njoinStatements cannot be resolved"
      + "\nsingleSource cannot be resolved");
  }
  
  public static Object toColumnType(final /* SqliteDataType */Object dt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field BLOB is undefined"
      + "\nColumnType cannot be resolved to a type."
      + "\nThe method or field INTEGER is undefined"
      + "\nColumnType cannot be resolved to a type."
      + "\nThe method or field REAL is undefined"
      + "\nColumnType cannot be resolved to a type."
      + "\nThe method or field TEXT is undefined"
      + "\nColumnType cannot be resolved to a type."
      + "\nThe method or field NONE is undefined"
      + "\nColumnType cannot be resolved to a type."
      + "\nThe method or field NUMERIC is undefined"
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nBLOB cannot be resolved"
      + "\nINTEGER cannot be resolved"
      + "\nREAL cannot be resolved"
      + "\nTEXT cannot be resolved"
      + "\nTEXT cannot be resolved"
      + "\nTEXT cannot be resolved"
      + "\nTEXT cannot be resolved");
  }
  
  public static String toJavaTypeName(final /* ColumnType */Object type) {
    throw new Error("Unresolved compilation problems:"
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nTEXT cannot be resolved"
      + "\nINTEGER cannot be resolved"
      + "\nREAL cannot be resolved"
      + "\nBLOB cannot be resolved"
      + "\nBOOLEAN cannot be resolved");
  }
  
  public static /* ColumnType */Object getInferredColumnType(final /* ResultColumn */Object col) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method getInferredColumnType(ResultColumn) from the type ModelUtil refers to the missing type ColumnType"
      + "\nexpression cannot be resolved");
  }
  
  public static /* ColumnType */Object getInferredColumnType(final /* ColumnSource */Object col) {
    throw new Error("Unresolved compilation problems:"
      + "\nColumnDef cannot be resolved to a type."
      + "\nResultColumn cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nUnreachable code: The case can never match. It is already handled by a previous condition."
      + "\nThe method getInferredColumnType(ColumnSource) from the type ModelUtil refers to the missing type ColumnType"
      + "\ntype cannot be resolved"
      + "\nexpression cannot be resolved"
      + "\nTEXT cannot be resolved");
  }
  
  public static /* ColumnType */Object getInferredColumnType(final /* Expression */Object expr) {
    throw new Error("Unresolved compilation problems:"
      + "\nCastExpression cannot be resolved to a type."
      + "\nColumnSourceRef cannot be resolved to a type."
      + "\nResultColumn cannot be resolved to a type."
      + "\nResultColumn cannot be resolved to a type."
      + "\nColumnDef cannot be resolved to a type."
      + "\nExprConcat cannot be resolved to a type."
      + "\nFunction cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nColumnType cannot be resolved to a type."
      + "\nUnreachable code: The case can never match. It is already handled by a previous condition."
      + "\nUnreachable code: The case can never match. It is already handled by a previous condition."
      + "\nUnreachable code: The case can never match. It is already handled by a previous condition."
      + "\nThe method toColumnType(SqliteDataType) from the type ModelUtil refers to the missing type Object"
      + "\nThe method getInferredColumnType(ColumnSource) from the type ModelUtil refers to the missing type ColumnType"
      + "\ntype cannot be resolved"
      + "\ncolumn cannot be resolved"
      + "\nsource cannot be resolved"
      + "\n== cannot be resolved"
      + "\nTEXT cannot be resolved"
      + "\ncolumn cannot be resolved"
      + "\nexpression cannot be resolved"
      + "\ncolumn cannot be resolved"
      + "\ntype cannot be resolved"
      + "\nTEXT cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\nINTEGER cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\nREAL cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\n|| cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequalsIgnoreCase cannot be resolved"
      + "\nBLOB cannot be resolved"
      + "\nTEXT cannot be resolved"
      + "\nTEXT cannot be resolved");
  }
  
  public static /* ArrayList<ColumnSource> */Object getViewResultColumns(final /* CreateViewStatement */Object stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nColumnSource cannot be resolved to a type."
      + "\nSelectCore cannot be resolved to a type."
      + "\nSelectExpression cannot be resolved to a type."
      + "\nSelectExpression cannot be resolved to a type."
      + "\nThe method or field name is undefined for the type Object"
      + "\nThe method or field name is undefined for the type Object"
      + "\nThe method or field name is undefined for the type Object"
      + "\nThe method or field name is undefined for the type Object"
      + "\ngetSelectStatement cannot be resolved"
      + "\ngetCore cannot be resolved"
      + "\ngetRight cannot be resolved"
      + "\ngetSelectList cannot be resolved"
      + "\n!= cannot be resolved"
      + "\ngetResultColumns cannot be resolved"
      + "\nfilter cannot be resolved"
      + "\n!= cannot be resolved"
      + "\n&& cannot be resolved"
      + "\nequals cannot be resolved"
      + "\n! cannot be resolved"
      + "\ngetSelectList cannot be resolved"
      + "\n!= cannot be resolved"
      + "\ngetResultColumns cannot be resolved"
      + "\nfilter cannot be resolved"
      + "\n!= cannot be resolved"
      + "\n&& cannot be resolved"
      + "\nequals cannot be resolved"
      + "\n! cannot be resolved");
  }
  
  public static /* HashSet<CreateViewStatement> */Object getAllViewsReferencingTable(final /* SqliteDatabaseSnapshot */Object snapshot, final /* TableDefinition */Object tableDef) {
    throw new Error("Unresolved compilation problems:"
      + "\nCreateViewStatement cannot be resolved to a type."
      + "\nThe method isDefinitionReferencedByView(TableDefinition, CreateViewStatement) from the type ModelUtil refers to the missing type TableDefinition"
      + "\nviews cannot be resolved");
  }
  
  public static /* HashSet<CreateViewStatement> */Object getAllViewsInConfigInitReferencingTable(final MickeyDatabaseModel model, final /* TableDefinition */Object tableDef) {
    throw new Error("Unresolved compilation problems:"
      + "\nCreateViewStatement cannot be resolved to a type."
      + "\nThe field MickeyDatabaseModel.initViews refers to the missing type CreateViewStatement"
      + "\nThe method isDefinitionReferencedByView(TableDefinition, CreateViewStatement) from the type ModelUtil refers to the missing type TableDefinition");
  }
  
  public static boolean isDefinitionReferencedByView(final /* TableDefinition */Object tableDef, final /* CreateViewStatement */Object view) {
    throw new Error("Unresolved compilation problems:"
      + "\nSingleSourceTable cannot be resolved to a type."
      + "\nCreateViewStatement cannot be resolved to a type."
      + "\nCreateViewStatement cannot be resolved to a type."
      + "\nThere is no context to infer the closure\'s argument types from. Consider typing the arguments or put the closures into a typed context."
      + "\nThe method isDefinitionReferencedByView(TableDefinition, CreateViewStatement) from the type ModelUtil refers to the missing type TableDefinition"
      + "\neAllContents cannot be resolved"
      + "\nexists cannot be resolved"
      + "\ntableReference cannot be resolved"
      + "\ntableReference cannot be resolved"
      + "\nname cannot be resolved"
      + "\nequals cannot be resolved"
      + "\nname cannot be resolved"
      + "\ntableReference cannot be resolved");
  }
  
  protected static Object _hasAndroidPrimaryKey(final /* CreateTableStatement */Object stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method getName() is undefined for the type Object"
      + "\ngetColumnDefs cannot be resolved"
      + "\nexists cannot be resolved"
      + "\nequals cannot be resolved");
  }
  
  protected static Object _hasAndroidPrimaryKey(final /* CreateViewStatement */Object stmt) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method getViewResultColumns(CreateViewStatement) from the type ModelUtil refers to the missing type ColumnSource"
      + "\ngetName cannot be resolved"
      + "\ngetName cannot be resolved"
      + "\nequals cannot be resolved");
  }
  
  /**
   * Find column definitions from caller going back to the definition
   */
  public static /* LinkedList<TableDefinition> */Object getHistory(final /* TableDefinition */Object ref) {
    throw new Error("Unresolved compilation problems:"
      + "\nTableDefinition cannot be resolved to a type."
      + "\nAlterTableRenameStatement cannot be resolved to a type."
      + "\ntable cannot be resolved");
  }
  
  public static /* MickeyFile */Object getModel(final EObject ele) {
    throw new Error("Unresolved compilation problems:"
      + "\nMickeyFile cannot be resolved to a type."
      + "\nMickeyFile cannot be resolved to a type.");
  }
  
  public static /* Iterable<MigrationBlock> */Object previousMigrations(final EObject ele) {
    throw new Error("Unresolved compilation problems:"
      + "\nMigrationBlock cannot be resolved to a type."
      + "\nThe method or field MigrationBlock is undefined"
      + "\nThe method or field from is undefined for the type Object");
  }
  
  public static <T extends Object> T getContainerOfType(final EObject element, final Class<T> type) {
    EObject ele = element;
    do {
      {
        EObject _eContainer = ele.eContainer();
        ele = _eContainer;
        boolean _equals = Objects.equal(ele, null);
        if (_equals) {
          return null;
        }
      }
    } while((!type.isAssignableFrom(ele.getClass())));
    return ((T) ele);
  }
  
  public static String getFeatureNodeText(final EObject obj, final EReference reference) {
    List<INode> nodes = NodeModelUtils.findNodesForFeature(obj, reference);
    INode _get = nodes.get(0);
    return NodeModelUtils.getTokenText(_get);
  }
  
  public static Object getAllColumnsForTableName(final ArrayList<EObject> allContents, final String tableName) {
    return null;
  }
  
  public static String getTargetTableName(final /* DMLStatement */Object statement) {
    throw new Error("Unresolved compilation problems:"
      + "\nUpdateStatement cannot be resolved to a type."
      + "\nInsertStatement cannot be resolved to a type."
      + "\nDeleteStatement cannot be resolved to a type."
      + "\nThe method or field MickeyLangPackage is undefined"
      + "\nThe method or field MickeyLangPackage is undefined"
      + "\nThe method or field MickeyLangPackage is undefined"
      + "\nUnreachable code: The case can never match. It is already handled by a previous condition."
      + "\nUnreachable code: The case can never match. It is already handled by a previous condition."
      + "\ngetFeatureNodeText cannot be resolved"
      + "\nLiterals cannot be resolved"
      + "\nUPDATE_STATEMENT__TABLE cannot be resolved"
      + "\ngetFeatureNodeText cannot be resolved"
      + "\nLiterals cannot be resolved"
      + "\nINSERT_STATEMENT__TABLE cannot be resolved"
      + "\ngetFeatureNodeText cannot be resolved"
      + "\nLiterals cannot be resolved"
      + "\nDELETE_STATEMENT__TABLE cannot be resolved");
  }
  
  public static Object hasAndroidPrimaryKey(final CreateTableStatement stmt) {
    if (stmt != null) {
      return _hasAndroidPrimaryKey(stmt);
    } else if (stmt != null) {
      return _hasAndroidPrimaryKey(stmt);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(stmt).toString());
    }
  }
}
