// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String CREATED_AT = "created_at";
// 
// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String REMOTE_ID = "remote_id";
// 
// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String UPDATED_AT = "updated_at";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_ASSETS = "assets";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_ENTRY_TYPES = "entry_types";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_LINKS = "links";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_SYNC_INFO = "sync_info";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String escape(String name) {
//   return String.format("`%s`", name);
// }
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String localizeName(String name, String locale) {
//   return String.format("%s$%s", name, locale);
// }


import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import com.contentful.java.cda.CDAAsset;
import com.contentful.java.cda.CDAEntry;
import com.contentful.java.cda.CDAResource;
import com.contentful.java.cda.CDAType;
import com.contentful.java.cda.LocalizedResource;
import com.contentful.java.cda.SynchronizedSpace;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import okhttp3.HttpUrl;
import static android.database.sqlite.SQLiteDatabase.CONFLICT_REPLACE;
import static com.contentful.java.cda.CDAType.ASSET;
import static com.contentful.java.cda.CDAType.ENTRY;
import static com.contentful.vault.BaseFields.CREATED_AT;
import static com.contentful.vault.BaseFields.REMOTE_ID;
import static com.contentful.vault.BaseFields.UPDATED_AT;
import static com.contentful.vault.Sql.TABLE_ASSETS;
import static com.contentful.vault.Sql.TABLE_ENTRY_TYPES;
import static com.contentful.vault.Sql.TABLE_LINKS;
import static com.contentful.vault.Sql.TABLE_SYNC_INFO;
import static com.contentful.vault.Sql.escape;
import static com.contentful.vault.Sql.localizeName;
    for (CDAEntry entry : syncedSpace.entries().values()) {
      processResource(entry);
    }
  }

  private void processDeleted(SynchronizedSpace syncedSpace) {
    for (String id : syncedSpace.deletedAssets()) {
      deleteAsset(id);
    }
    for (String id : syncedSpace.deletedEntries()) {
      deleteEntry(id);
    }
  }

  private String fetchSyncToken() {
    String token = null;
    Cursor cursor = db.rawQuery("SELECT `token` FROM sync_info", null);
    try {
      if (cursor.moveToFirst()) {
        token = cursor.getString(0);
      }
    } finally {
      cursor.close();
    }
    return token;
  }

  private void saveSyncInfo(String syncToken) {
    AutoEscapeValues values = new AutoEscapeValues();
    values.put("token", syncToken);
// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String CREATED_AT = "created_at";
// 
// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String REMOTE_ID = "remote_id";
// 
// Path: core/src/main/java/com/contentful/vault/BaseFields.java
// public static final String UPDATED_AT = "updated_at";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_ASSETS = "assets";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_ENTRY_TYPES = "entry_types";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_LINKS = "links";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static final String TABLE_SYNC_INFO = "sync_info";
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String escape(String name) {
//   return String.format("`%s`", name);
// }
// 
// Path: core/src/main/java/com/contentful/vault/Sql.java
// static String localizeName(String name, String locale) {
//   return String.format("%s$%s", name, locale);
// }


// Path: core/src/main/java/com/contentful/vault/SyncRunnable.java
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import com.contentful.java.cda.CDAAsset;
import com.contentful.java.cda.CDAEntry;
import com.contentful.java.cda.CDAResource;
import com.contentful.java.cda.CDAType;
import com.contentful.java.cda.LocalizedResource;
import com.contentful.java.cda.SynchronizedSpace;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import okhttp3.HttpUrl;
import static android.database.sqlite.SQLiteDatabase.CONFLICT_REPLACE;
import static com.contentful.java.cda.CDAType.ASSET;
import static com.contentful.java.cda.CDAType.ENTRY;
import static com.contentful.vault.BaseFields.CREATED_AT;
import static com.contentful.vault.BaseFields.REMOTE_ID;
import static com.contentful.vault.BaseFields.UPDATED_AT;
import static com.contentful.vault.Sql.TABLE_ASSETS;
import static com.contentful.vault.Sql.TABLE_ENTRY_TYPES;
import static com.contentful.vault.Sql.TABLE_LINKS;
import static com.contentful.vault.Sql.TABLE_SYNC_INFO;
import static com.contentful.vault.Sql.escape;
import static com.contentful.vault.Sql.localizeName;

    for (CDAEntry entry : syncedSpace.entries().values()) {
      processResource(entry);
    }
  }

  private void processDeleted(SynchronizedSpace syncedSpace) {
    for (String id : syncedSpace.deletedAssets()) {
      deleteAsset(id);
    }
    for (String id : syncedSpace.deletedEntries()) {
      deleteEntry(id);
    }
  }

  private String fetchSyncToken() {
    String token = null;
    Cursor cursor = db.rawQuery("SELECT `token` FROM sync_info", null);
    try {
      if (cursor.moveToFirst()) {
        token = cursor.getString(0);
      }
    } finally {
      cursor.close();
    }
    return token;
  }

  private void saveSyncInfo(String syncToken) {
    AutoEscapeValues values = new AutoEscapeValues();
    values.put("token", syncToken);
    db.delete(TABLE_SYNC_INFO, null, null);