// 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/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 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.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.contentful.java.cda.CDAType.ASSET;
import static com.contentful.vault.BaseFields.REMOTE_ID;
import static com.contentful.vault.Sql.TABLE_ENTRY_TYPES;
import static com.contentful.vault.Sql.TABLE_LINKS;
import static com.contentful.vault.Sql.escape;
import static com.contentful.vault.Sql.localizeName;
/*
 * 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;



final class LinkResolver {
  private static final String LINKS_WHERE_CLAUSE =
      "l.parent = ? AND l.is_asset = ? AND l.field = ?";

  private static final String QUERY_ENTRY_TYPE = String.format(
      "SELECT `type_id` FROM %s WHERE %s = ?", TABLE_ENTRY_TYPES, REMOTE_ID);

  private final AbsQuery<?, ?> query;

  private final Map<String, Resource> assets;

  private final Map<String, Resource> entries;

  LinkResolver(AbsQuery<?, ?> query, Map<String, Resource> assets, Map<String, Resource> entries) {
    this.query = query;
    this.assets = assets;
    this.entries = entries;
  }

  void resolveLinks(Resource resource, List<FieldMeta> links, String locale) {
    for (FieldMeta field : links) {
      if (field.isLink() || field.isArrayOfLinks()) {
// 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/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 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/LinkResolver.java
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.contentful.java.cda.CDAType.ASSET;
import static com.contentful.vault.BaseFields.REMOTE_ID;
import static com.contentful.vault.Sql.TABLE_ENTRY_TYPES;
import static com.contentful.vault.Sql.TABLE_LINKS;
import static com.contentful.vault.Sql.escape;
import static com.contentful.vault.Sql.localizeName;

/*
 * 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;



final class LinkResolver {
  private static final String LINKS_WHERE_CLAUSE =
      "l.parent = ? AND l.is_asset = ? AND l.field = ?";

  private static final String QUERY_ENTRY_TYPE = String.format(
      "SELECT `type_id` FROM %s WHERE %s = ?", TABLE_ENTRY_TYPES, REMOTE_ID);

  private final AbsQuery<?, ?> query;

  private final Map<String, Resource> assets;

  private final Map<String, Resource> entries;

  LinkResolver(AbsQuery<?, ?> query, Map<String, Resource> assets, Map<String, Resource> entries) {
    this.query = query;
    this.assets = assets;
    this.entries = entries;
  }

  void resolveLinks(Resource resource, List<FieldMeta> links, String locale) {
    for (FieldMeta field : links) {
      if (field.isLink() || field.isArrayOfLinks()) {
        resolveLinksForField(resource, field, locale);