package com.justeat.mickeydb;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.justeat.mickeydb.MickeyDatabaseModel;
import com.justeat.mickeydb.MickeyModel;
import com.justeat.mickeydb.generator.SqliteDatabaseSnapshot;
import com.justeat.mickeydb.mickeyLang.MickeyFile;
import com.justeat.mickeydb.mickeyLang.MigrationBlock;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;

@SuppressWarnings("all")
public class MickeyAssembler {
  @Inject
  private Provider<SqliteDatabaseSnapshot.Builder> mDbSnapshotBuilderProvider;
  
  public MickeyModel assemble(final Resource resource) {
    ResourceSet _resourceSet = resource.getResourceSet();
    EList<Resource> _resources = _resourceSet.getResources();
    final Function1<Resource, MickeyFile> _function = (Resource it) -> {
      TreeIterator<EObject> _allContents = it.getAllContents();
      EObject _head = IteratorExtensions.<EObject>head(_allContents);
      return ((MickeyFile) _head);
    };
    List<MickeyFile> _map = ListExtensions.<Resource, MickeyFile>map(_resources, _function);
    return this.assemble(_map, null);
  }
  
  public MickeyModel assemble(final Resource resource, final MigrationBlock upToMigration) {
    ResourceSet _resourceSet = resource.getResourceSet();
    EList<Resource> _resources = _resourceSet.getResources();
    final Function1<Resource, MickeyFile> _function = (Resource it) -> {
      TreeIterator<EObject> _allContents = it.getAllContents();
      EObject _head = IteratorExtensions.<EObject>head(_allContents);
      return ((MickeyFile) _head);
    };
    List<MickeyFile> _map = ListExtensions.<Resource, MickeyFile>map(_resources, _function);
    return this.assemble(_map, upToMigration);
  }
  
  public MickeyModel assemble(final List<MickeyFile> files) {
    return this.assemble(files, null);
  }
  
  public MickeyModel assemble(final List<MickeyFile> files, final MigrationBlock upToMigration) {
    throw new Error("Unresolved compilation problems:"
      + "\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 field MickeyDatabaseModel.initTables refers to the missing type CreateTableStatement"
      + "\nThe field MickeyDatabaseModel.initViews refers to the missing type CreateViewStatement"
      + "\nThe method setSnapshot(SqliteDatabaseSnapshot) from the type MickeyDatabaseModel refers to the missing type SqliteDatabaseSnapshot"
      + "\nThe method getSnapshot() from the type MickeyDatabaseModel refers to the missing type SqliteDatabaseSnapshot"
      + "\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 getSnapshot() from the type MickeyDatabaseModel refers to the missing type SqliteDatabaseSnapshot"
      + "\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 getSnapshot() from the type MickeyDatabaseModel refers to the missing type SqliteDatabaseSnapshot"
      + "\nThere is no context to infer the closure\'s argument types from. Consider typing the arguments or put the closures into a typed context."
      + "\nname cannot be resolved"
      + "\nname cannot be resolved"
      + "\ntables cannot be resolved"
      + "\nsortInplaceBy cannot be resolved"
      + "\nviews cannot be resolved"
      + "\nsortInplaceBy cannot be resolved"
      + "\ntriggers cannot be resolved"
      + "\nsortInplaceBy cannot be resolved");
  }
  
  private void sortMigrations(final MickeyDatabaseModel db, final MigrationBlock upToMigration) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe method or field from is undefined"
      + "\nThe field MickeyDatabaseModel.migrationsByName refers to the missing type MigrationBlock"
      + "\nThe field MickeyDatabaseModel.migrations refers to the missing type MigrationBlock"
      + "\nThe field MickeyDatabaseModel.migrationsByFromName refers to the missing type MigrationBlock"
      + "\n== cannot be resolved"
      + "\n== cannot be resolved"
      + "\n!= cannot be resolved"
      + "\nname cannot be resolved"
      + "\nname cannot be resolved");
  }
  
  private MickeyDatabaseModel registerFile(final MickeyModel model, final MickeyFile file) {
    throw new Error("Unresolved compilation problems:"
      + "\nThe field MickeyDatabaseModel.actions refers to the missing type ActionStatement"
      + "\nThe field MickeyDatabaseModel.functions refers to the missing type MickeyFunction"
      + "\nThe field MickeyDatabaseModel.initTables refers to the missing type CreateTableStatement"
      + "\nThe field MickeyDatabaseModel.initViews refers to the missing type CreateViewStatement"
      + "\nThe field MickeyDatabaseModel.migrationsByName refers to the missing type MigrationBlock"
      + "\nThe field MickeyDatabaseModel.migrationsByFromName refers to the missing type MigrationBlock");
  }
}
