'use strict';

var servicesModule = require('./_index.js');

/**
 * @ngInject
 */
function SearchService($q, $http, AppSettings) {

  var service = {};

  service.getData = function(term) {
    var deferred = $q.defer();

    $http.jsonp(AppSettings.apiUrl+'search.json?callback=JSON_CALLBACK', {
      params: {q: term}
    }).success(function(data) {
        deferred.resolve(data);
    }).error(function(err, status) {
        deferred.reject(err, status);
    });

    return deferred.promise;
  };

  service.getLocationSuggestions = function(term) {
    var deferred = $q.defer();
    $http.jsonp(AppSettings.apiUrl+'suggest.json?callback=JSON_CALLBACK', {
      params: {q: term}
    }).success(function(data) {
        deferred.resolve(data);
    }).error(function(err, status) {
        deferred.reject(err, status);
    });

    return deferred.promise;
  };

  service.initData = function(paramsObj) {
    var deferred = $q.defer();
    //paramsObj.q = decodeURIComponent(paramsObj.q);
    $http.jsonp(AppSettings.apiUrl+'search.json?callback=JSON_CALLBACK', {
      params: paramsObj
    }).success(function(data) {
        deferred.resolve(data);
    }).error(function(err, status) {
        deferred.reject(err, status);
    });

    return deferred.promise;
  };

  service.retrieveImg = function(statusID) {
    var deferred = $q.defer();
    $http.jsonp(AppSettings.apiUrl+'search.json?callback=JSON_CALLBACK', {
      params: {q : 'id:' + statusID}
    }).success(function(data) {
        deferred.resolve(data);
    }).error(function(err, status) {
        deferred.reject(err, status);
    });

    return deferred.promise;
  };

  return service;

}

servicesModule.service('SearchService',['$q', '$http', 'AppSettings', SearchService]);

@@ -663,39 +663,78 @@
 %0A      params: %7B
-q: term
+%0A        q: term,%0A        source: %22geo%22%0A      
 %7D%0A    %7D).success

Add source=geo to location suggestion query