// Path: core/src/main/java/com/contentful/vault/ModelHelper.java
// public abstract class ModelHelper<T extends Resource> {
//   public abstract String getTableName();
// 
//   public abstract List<FieldMeta> getFields();
// 
//   public abstract List<String> getCreateStatements(SpaceHelper spaceHelper);
// 
//   public abstract T fromCursor(Cursor cursor);
// 
//   protected abstract boolean setField(T resource, String name, Object value);
// 
//   protected final <E extends Serializable> E fieldFromBlob(Class<E> clazz, Cursor cursor,
//       int columnIndex) {
//     byte[] blob = cursor.getBlob(columnIndex);
//     if (blob == null || blob.length == 0) {
//       return null;
//     }
//     E result = null;
//     Exception exception = null;
//     try {
//       result = BlobUtils.fromBlob(clazz, blob);
//     } catch (IOException | ClassNotFoundException e) {
//       exception = e;
//     }
//     if (exception != null) {
//       throw new RuntimeException(String.format("Failed creating BLOB from column %d of %s.",
//           columnIndex, getTableName()), exception);
//     }
//     return result;
//   }
// 
//   protected final void setContentType(T resource, String type) {
//     resource.setContentType(type);
//   }
// }
// 
// Path: core/src/main/java/com/contentful/vault/Resource.java
// public abstract class Resource {
//   String remoteId;
// 
//   String createdAt;
// 
//   String updatedAt;
// 
//   String contentType;
// 
//   public String remoteId() {
//     return remoteId;
//   }
// 
//   public String createdAt() {
//     return createdAt;
//   }
// 
//   public String updatedAt() {
//     return updatedAt;
//   }
// 
//   void setRemoteId(String remoteId) {
//     this.remoteId = remoteId;
//   }
// 
//   void setCreatedAt(String createdAt) {
//     this.createdAt = createdAt;
//   }
// 
//   void setUpdatedAt(String updatedAt) {
//     this.updatedAt = updatedAt;
//   }
// 
//   void setContentType(String contentType) {
//     this.contentType = contentType;
//   }
// 
//   String contentType() {
//     return contentType;
//   }
// 
//   String getIdPrefix() {
//     return null;
//   }
// 
//   @Override public boolean equals(Object o) {
//     if (this == o) return true;
//     if (!(o instanceof Resource)) return false;
// 
//     Resource resource = (Resource) o;
//     String prefix = StringUtils.defaultString(getIdPrefix(), "");
//     if (!prefix.equals(StringUtils.defaultString(resource.getIdPrefix(), ""))) return false;
//     return (prefix + remoteId()).equals(prefix + resource.remoteId());
//   }
// 
//   @Override public int hashCode() {
//     return (StringUtils.defaultString(getIdPrefix(), "") + remoteId).hashCode();
//   }
// }
// 
// Path: core/src/main/java/com/contentful/vault/SpaceHelper.java
// public abstract class SpaceHelper {
//   public abstract String getDatabaseName();
// 
//   public abstract int getDatabaseVersion();
// 
//   public abstract Map<Class<?>, ModelHelper<?>> getModels();
// 
//   public abstract Map<String, Class<? extends Resource>> getTypes();
// 
//   public abstract String getCopyPath();
// 
//   public abstract String getSpaceId();
// 
//   public abstract List<String> getLocales();
// 
//   public final String getDefaultLocale() {
//     return getLocales().get(0);
//   }
// }


import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import com.contentful.vault.ModelHelper;
import com.contentful.vault.Resource;
import com.contentful.vault.SpaceHelper;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.WildcardTypeName;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
/*
 * Copyright (C) 2018 Contentful GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.contentful.vault.compiler;


final class SpaceInjection extends Injection {
  private final List<ModelInjection> models;

  private final String dbName;

  private final int dbVersion;

  private final String copyPath;

  private final List<String> locales;

  private FieldSpec specModels;

  private FieldSpec specTypes;

  public SpaceInjection(String remoteId, ClassName className, TypeElement originatingElement,
      List<ModelInjection> models, String dbName, int dbVersion, String copyPath,
      List<String> locales) {
    super(remoteId, className, originatingElement);
    this.models = models;
    this.dbName = dbName;
    this.dbVersion = dbVersion;
    this.copyPath = copyPath;
    this.locales = locales;
  }

  @Override TypeSpec.Builder getTypeSpecBuilder() {
    TypeSpec.Builder builder = TypeSpec.classBuilder(className.simpleName())
// Path: core/src/main/java/com/contentful/vault/ModelHelper.java
// public abstract class ModelHelper<T extends Resource> {
//   public abstract String getTableName();
// 
//   public abstract List<FieldMeta> getFields();
// 
//   public abstract List<String> getCreateStatements(SpaceHelper spaceHelper);
// 
//   public abstract T fromCursor(Cursor cursor);
// 
//   protected abstract boolean setField(T resource, String name, Object value);
// 
//   protected final <E extends Serializable> E fieldFromBlob(Class<E> clazz, Cursor cursor,
//       int columnIndex) {
//     byte[] blob = cursor.getBlob(columnIndex);
//     if (blob == null || blob.length == 0) {
//       return null;
//     }
//     E result = null;
//     Exception exception = null;
//     try {
//       result = BlobUtils.fromBlob(clazz, blob);
//     } catch (IOException | ClassNotFoundException e) {
//       exception = e;
//     }
//     if (exception != null) {
//       throw new RuntimeException(String.format("Failed creating BLOB from column %d of %s.",
//           columnIndex, getTableName()), exception);
//     }
//     return result;
//   }
// 
//   protected final void setContentType(T resource, String type) {
//     resource.setContentType(type);
//   }
// }
// 
// Path: core/src/main/java/com/contentful/vault/Resource.java
// public abstract class Resource {
//   String remoteId;
// 
//   String createdAt;
// 
//   String updatedAt;
// 
//   String contentType;
// 
//   public String remoteId() {
//     return remoteId;
//   }
// 
//   public String createdAt() {
//     return createdAt;
//   }
// 
//   public String updatedAt() {
//     return updatedAt;
//   }
// 
//   void setRemoteId(String remoteId) {
//     this.remoteId = remoteId;
//   }
// 
//   void setCreatedAt(String createdAt) {
//     this.createdAt = createdAt;
//   }
// 
//   void setUpdatedAt(String updatedAt) {
//     this.updatedAt = updatedAt;
//   }
// 
//   void setContentType(String contentType) {
//     this.contentType = contentType;
//   }
// 
//   String contentType() {
//     return contentType;
//   }
// 
//   String getIdPrefix() {
//     return null;
//   }
// 
//   @Override public boolean equals(Object o) {
//     if (this == o) return true;
//     if (!(o instanceof Resource)) return false;
// 
//     Resource resource = (Resource) o;
//     String prefix = StringUtils.defaultString(getIdPrefix(), "");
//     if (!prefix.equals(StringUtils.defaultString(resource.getIdPrefix(), ""))) return false;
//     return (prefix + remoteId()).equals(prefix + resource.remoteId());
//   }
// 
//   @Override public int hashCode() {
//     return (StringUtils.defaultString(getIdPrefix(), "") + remoteId).hashCode();
//   }
// }
// 
// Path: core/src/main/java/com/contentful/vault/SpaceHelper.java
// public abstract class SpaceHelper {
//   public abstract String getDatabaseName();
// 
//   public abstract int getDatabaseVersion();
// 
//   public abstract Map<Class<?>, ModelHelper<?>> getModels();
// 
//   public abstract Map<String, Class<? extends Resource>> getTypes();
// 
//   public abstract String getCopyPath();
// 
//   public abstract String getSpaceId();
// 
//   public abstract List<String> getLocales();
// 
//   public final String getDefaultLocale() {
//     return getLocales().get(0);
//   }
// }


// Path: compiler/src/main/java/com/contentful/vault/compiler/SpaceInjection.java
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import com.contentful.vault.ModelHelper;
import com.contentful.vault.Resource;
import com.contentful.vault.SpaceHelper;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.WildcardTypeName;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

/*
 * Copyright (C) 2018 Contentful GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.contentful.vault.compiler;


final class SpaceInjection extends Injection {
  private final List<ModelInjection> models;

  private final String dbName;

  private final int dbVersion;

  private final String copyPath;

  private final List<String> locales;

  private FieldSpec specModels;

  private FieldSpec specTypes;

  public SpaceInjection(String remoteId, ClassName className, TypeElement originatingElement,
      List<ModelInjection> models, String dbName, int dbVersion, String copyPath,
      List<String> locales) {
    super(remoteId, className, originatingElement);
    this.models = models;
    this.dbName = dbName;
    this.dbVersion = dbVersion;
    this.copyPath = copyPath;
    this.locales = locales;
  }

  @Override TypeSpec.Builder getTypeSpecBuilder() {
    TypeSpec.Builder builder = TypeSpec.classBuilder(className.simpleName())
        .superclass(ClassName.get(SpaceHelper.class))