import { Service } from 'esri-leaflet';
import { WorldGeocodingServiceUrl } from '../EsriLeafletGeocoding';
import geocode from '../Tasks/Geocode';
import reverseGeocode from '../Tasks/ReverseGeocode';
import suggest from '../Tasks/Suggest';

export var GeocodeService = Service.extend({
  initialize: function (options) {
    options = options || {};
    options.url = options.url || WorldGeocodingServiceUrl;
    Service.prototype.initialize.call(this, options);
    this._confirmSuggestSupport();
  },

  geocode: function () {
    return geocode(this);
  },

  reverse: function () {
    return reverseGeocode(this);
  },

  suggest: function () {
    // requires either the Esri World Geocoding Service or a 10.3 ArcGIS Server Geocoding Service that supports suggest.
    return suggest(this);
  },

  _confirmSuggestSupport: function () {
    this.metadata(function (error, response) {
      if (error) { return; }
      if (response.capabilities.includes('Suggest')) {
        this.options.supportsSuggest = true;
      } else {
        this.options.supportsSuggest = false;
      }
    }, this);
  }
});

export function geocodeService (options) {
  return new GeocodeService(options);
}

export default geocodeService;

@@ -952,14 +952,13 @@
 s.in
-cludes
+dexOf
 ('Su
@@ -964,16 +964,21 @@
 uggest')
+ %3E -1
 ) %7B%0A    

use indexOf instead of includes for ie (#127)