/**
   * Queries for <tt>CapitalMarketsOrder</tt> with the provided <tt>scope</tt> in the background.
   *
   * <p>Note: the scopes were defined from the Designer.
   *
   * <p>The {@link import com.anypresence.sdk.callbacks.APCallback} callback allows you to run code
   * in the main UI thread.
   *
   * <p>Example:
   *
   * <pre>{@code
   * Map<String,String> params = new HashMap<String,String>();
   * params.put("name", "test");
   * CapitalMarketsOrder.queryInBackground("all", params, 0, 25, new APCallback<List<CapitalMarketsOrder>>() {
   *
   *     public void finished(List<CapitalMarketsOrder> objects, Throwable ex) {
   *         if (ex == null) {
   *             Log.i(TAG, "Objects fetched!");
   *         } else {
   *             Log.e(TAG, "Unable to fetch objects!", ex);
   *         }
   *     }
   * });
   * }</pre>
   *
   * @see import com.anypresence.sdk.callbacks.APCallback
   * @param scope the scope to perform the query.
   * @param params a map of parameters.
   * @param offset offset for the query, or <tt>null</tt> for no offset.
   * @param limit max results to return back, <tt>null</tt> for no limit.
   * @param futureCallback the callback that handles the result of the request.
   */
  public static List<CapitalMarketsOrder> queryInBackground(
      final String scope,
      Map<String, String> params,
      Integer offset,
      Integer limit,
      IAPFutureCallback<List<CapitalMarketsOrder>> futureCallback) {

    RemoteRequest.RemoteRequestBuilder remoteRequestBuilder =
        RemoteRailsConfig.getRouterAdapterByClassOrUseDefaultAdapter(CapitalMarketsOrder.class)
            .createRemoteRequestBuilder(scope, RequestMethod.GET, CapitalMarketsOrder.class);
    remoteRequestBuilder.query(scope);
    if (params != null) {
      remoteRequestBuilder.addToParameters(params);
      remoteRequestBuilder.context(params);
    }

    if (offset != null) {
      remoteRequestBuilder.addToParameters("offset", offset.toString());
    }

    if (limit != null) {
      remoteRequestBuilder.addToParameters("limit", limit.toString());
    }

    RemoteRequest remoteRequest = remoteRequestBuilder.createRemoteRequest();

    if (DEBUG_MODE) {
      System.out.println(ReflectionToStringBuilder.reflectionToString(remoteRequest));
    }

    return com.anypresence.sdk.APObject.queryInBackground(
        remoteRequest, CapitalMarketsOrder.class, futureCallback);
  }
  /**
   * Fetches a <tt>CapitalMarketsOrder</tt> with the provided <tt>objectId</tt>.
   *
   * @param objectId the id of the object
   * @return an instance of <tt>CapitalMarketsOrder</tt>
   * @throws RemoteRequestException If there are other issues with the request.
   */
  public static CapitalMarketsOrder fetch(String objectId) throws RemoteRequestException {
    RemoteRequest.RemoteRequestBuilder remoteRequestBuilder =
        RemoteRailsConfig.getRouterAdapterByClassOrUseDefaultAdapter(CapitalMarketsOrder.class)
            .createRemoteRequestBuilder(RequestMethod.GET, CapitalMarketsOrder.class);

    CapitalMarketsOrder object = new CapitalMarketsOrder();
    object.setObjectIdAsString(objectId);

    remoteRequestBuilder.context(object);

    RemoteRequest remoteRequest = remoteRequestBuilder.createRemoteRequest();
    remoteRequest = Utility.interpolateRemoteRequest(remoteRequest);

    return com.anypresence.sdk.APObject.fetch(remoteRequest, CapitalMarketsOrder.class);
  }
  /**
   * Queries for <tt>CapitalMarketsOrder</tt> with the provided <tt>scope</tt> and other params.
   *
   * <p>Note: the scopes were defined from the Designer.
   *
   * @param scope the scope to perform the query.
   * @param params a map of parameters.
   * @param offset offset for the query, or <tt>null</tt> for no offset.
   * @param limit max results to return back, <tt>null</tt> for no limit.
   * @throws RemoteRequestException If there are other issues with the request.
   */
  public static List<CapitalMarketsOrder> query(
      String scope, Map<String, String> params, Integer offset, Integer limit)
      throws RemoteRequestException {
    RemoteRequest.RemoteRequestBuilder remoteRequestBuilder =
        RemoteRailsConfig.getRouterAdapterByClassOrUseDefaultAdapter(CapitalMarketsOrder.class)
            .createRemoteRequestBuilder(scope, RequestMethod.GET, CapitalMarketsOrder.class);
    remoteRequestBuilder.query(scope);
    if (params != null) {
      remoteRequestBuilder.addToParameters(params);
      remoteRequestBuilder.context(params);
    }
    if (offset != null) {
      remoteRequestBuilder.addToParameters("offset", offset.toString());
    }

    if (limit != null) {
      remoteRequestBuilder.addToParameters("limit", limit.toString());
    }
    RemoteRequest remoteRequest = remoteRequestBuilder.createRemoteRequest();

    return com.anypresence.sdk.APObject.query(
        remoteRequest, offset, limit, CapitalMarketsOrder.class);
  }