// Path: app/src/main/java/discovery/contentful/api/CFClient.java
// public class CFClient {
//   private static CDAClient sInstance;
//   private static String locale;
// 
//   private CFClient() {
//   }
// 
//   /**
//    * Initialize this client.
//    *
//    * @param space String representing the Space key.
//    * @param token String representing the access token required to log in to the Space.
//    * @return {@link com.contentful.java.cda.CDAClient} instance.
//    */
//   public synchronized static CDAClient init(String space, String token) {
//     SharedPreferences prefs = CFPrefs.getInstance();
// 
//     prefs.edit()
//         .putString(CFPrefs.KEY_SPACE, space)
//         .putString(CFPrefs.KEY_ACCESS_TOKEN, token)
//         .apply();
// 
//     sInstance = CDAClient.builder().setSpace(space).setToken(token).build();
// 
//     locale = null;
// 
//     return sInstance;
//   }
// 
//   public synchronized static CDAClient getClient() {
//     if (sInstance == null) {
//       SharedPreferences prefs = CFPrefs.getInstance();
// 
//       String space = prefs.getString(CFPrefs.KEY_SPACE, null);
//       String token = prefs.getString(CFPrefs.KEY_ACCESS_TOKEN, null);
// 
//       if (StringUtils.isBlank(space) || StringUtils.isBlank(token)) {
//         throw new IllegalStateException("Uninitialized client.");
//       }
// 
//       return init(space, token);
//     }
// 
//     return sInstance;
//   }
// 
//   /**
//    * Set the locale for this client.
//    *
//    * @param locale String representing the Locale code.
//    */
//   public synchronized static void setLocale(String locale) {
//     CFClient.locale = locale;
//   }
// 
//   /**
//    * Gets the current locale defined for this client.
//    *
//    * @return String representing the current configured locale, null in case the default
//    * locale is being used.
//    */
//   public static String getLocale() {
//     return locale;
//   }
// }
// 
// Path: app/src/main/java/discovery/contentful/api/ResourceList.java
// public class ResourceList {
//   public List<CDAResource> resources;
//   public Map<String, CDAContentType> contentTypes;
// }


import com.contentful.java.cda.CDAArray;
import com.contentful.java.cda.CDAClient;
import com.contentful.java.cda.CDAContentType;
import com.contentful.java.cda.CDAEntry;
import com.contentful.java.cda.FetchQuery;
import discovery.contentful.api.CFClient;
import discovery.contentful.api.ResourceList;
import java.util.ArrayList;
package discovery.contentful.loaders;


public class EntriesByContentTypeLoader extends AbsResourceListLoader {
  private final CDAContentType contentType;

  public EntriesByContentTypeLoader(CDAContentType contentType) {
    super();
    this.contentType = contentType;
  }

  @Override protected ResourceList performLoad(CDAClient client) {
    ResourceList resourceList = new ResourceList();

    FetchQuery<CDAEntry> query =
        client.fetch(CDAEntry.class).where("content_type", contentType.id());

    // Set the locale if non-default locale is currently configured
// Path: app/src/main/java/discovery/contentful/api/CFClient.java
// public class CFClient {
//   private static CDAClient sInstance;
//   private static String locale;
// 
//   private CFClient() {
//   }
// 
//   /**
//    * Initialize this client.
//    *
//    * @param space String representing the Space key.
//    * @param token String representing the access token required to log in to the Space.
//    * @return {@link com.contentful.java.cda.CDAClient} instance.
//    */
//   public synchronized static CDAClient init(String space, String token) {
//     SharedPreferences prefs = CFPrefs.getInstance();
// 
//     prefs.edit()
//         .putString(CFPrefs.KEY_SPACE, space)
//         .putString(CFPrefs.KEY_ACCESS_TOKEN, token)
//         .apply();
// 
//     sInstance = CDAClient.builder().setSpace(space).setToken(token).build();
// 
//     locale = null;
// 
//     return sInstance;
//   }
// 
//   public synchronized static CDAClient getClient() {
//     if (sInstance == null) {
//       SharedPreferences prefs = CFPrefs.getInstance();
// 
//       String space = prefs.getString(CFPrefs.KEY_SPACE, null);
//       String token = prefs.getString(CFPrefs.KEY_ACCESS_TOKEN, null);
// 
//       if (StringUtils.isBlank(space) || StringUtils.isBlank(token)) {
//         throw new IllegalStateException("Uninitialized client.");
//       }
// 
//       return init(space, token);
//     }
// 
//     return sInstance;
//   }
// 
//   /**
//    * Set the locale for this client.
//    *
//    * @param locale String representing the Locale code.
//    */
//   public synchronized static void setLocale(String locale) {
//     CFClient.locale = locale;
//   }
// 
//   /**
//    * Gets the current locale defined for this client.
//    *
//    * @return String representing the current configured locale, null in case the default
//    * locale is being used.
//    */
//   public static String getLocale() {
//     return locale;
//   }
// }
// 
// Path: app/src/main/java/discovery/contentful/api/ResourceList.java
// public class ResourceList {
//   public List<CDAResource> resources;
//   public Map<String, CDAContentType> contentTypes;
// }


// Path: app/src/main/java/discovery/contentful/loaders/EntriesByContentTypeLoader.java
import com.contentful.java.cda.CDAArray;
import com.contentful.java.cda.CDAClient;
import com.contentful.java.cda.CDAContentType;
import com.contentful.java.cda.CDAEntry;
import com.contentful.java.cda.FetchQuery;
import discovery.contentful.api.CFClient;
import discovery.contentful.api.ResourceList;
import java.util.ArrayList;

package discovery.contentful.loaders;


public class EntriesByContentTypeLoader extends AbsResourceListLoader {
  private final CDAContentType contentType;

  public EntriesByContentTypeLoader(CDAContentType contentType) {
    super();
    this.contentType = contentType;
  }

  @Override protected ResourceList performLoad(CDAClient client) {
    ResourceList resourceList = new ResourceList();

    FetchQuery<CDAEntry> query =
        client.fetch(CDAEntry.class).where("content_type", contentType.id());

    // Set the locale if non-default locale is currently configured
    String locale = CFClient.getLocale();