/**
* BeNomad BeMap JavaScript API - GeoServerInfoResponse
*
* Response from `POST service/geoServerInfo/1.0` — the metadata for the
* geoserver named in the request: the list of services it exposes, the
* supported travel modes, the per-service resource limits, plus the
* copyright and supplier-terms strings the customer application is
* required to display.
*
* Wire shape (verified against a live beta response):
*
* {
* "availableGeoServerNames": ["osm","addok","here","nominatim"],
* "globalCopyright": "Here Maps 2026.1",
* "globalCopyrightUrl": "https://company.here.com/here/",
* "globalSupplierTerms": "Supplier Terms Applicable to Location Content",
* "globalSupplierTermsUrl": "http://corporate.navteq.com/supplier_terms.html",
* "transportTypes": ["PEDESTRIAN","BICYCLE","MOTORCYCLE","CAR",...],
* "truckAttributes": true,
* "servicesInfo": [{ fieldName, serviceName, title, description }, ...],
* "serviceLimits": [{ serviceName, key, argument, type, value, unit }, ...]
* }
*
* @since 1.5.0
* @public
* @constructor
*/
bemap.GeoServerInfoResponse = function(options) {
var opts = options || {};
this.availableGeoServerNames = Array.isArray(opts.availableGeoServerNames) ? opts.availableGeoServerNames.slice() : [];
this.globalCopyright = opts.globalCopyright || null;
this.globalCopyrightUrl = opts.globalCopyrightUrl || null;
this.globalSupplierTerms = opts.globalSupplierTerms || null;
this.globalSupplierTermsUrl = opts.globalSupplierTermsUrl || null;
this.transportTypes = Array.isArray(opts.transportTypes) ? opts.transportTypes.slice() : [];
this.truckAttributes = (opts.truckAttributes === true);
this.servicesInfo = Array.isArray(opts.servicesInfo) ? opts.servicesInfo : [];
this.serviceLimits = Array.isArray(opts.serviceLimits) ? opts.serviceLimits : [];
};
bemap.GeoServerInfoResponse.prototype.getAvailableGeoServerNames = function() { return this.availableGeoServerNames; };
bemap.GeoServerInfoResponse.prototype.getGlobalCopyright = function() { return this.globalCopyright; };
bemap.GeoServerInfoResponse.prototype.getGlobalCopyrightUrl = function() { return this.globalCopyrightUrl; };
bemap.GeoServerInfoResponse.prototype.getGlobalSupplierTerms = function() { return this.globalSupplierTerms; };
bemap.GeoServerInfoResponse.prototype.getGlobalSupplierTermsUrl = function() { return this.globalSupplierTermsUrl; };
bemap.GeoServerInfoResponse.prototype.getTransportTypes = function() { return this.transportTypes; };
bemap.GeoServerInfoResponse.prototype.isTruckAttributes = function() { return this.truckAttributes; };
bemap.GeoServerInfoResponse.prototype.getServicesInfo = function() { return this.servicesInfo; };
bemap.GeoServerInfoResponse.prototype.getServiceLimits = function() { return this.serviceLimits; };
/**
* `true` when the selected geoserver exposes the named service.
*
* info.hasService('Routing') // true / false
* info.hasService('NearPoi') // true / false
*
* @public
* @param {String} serviceName As emitted by the server (`'Routing'`, `'Geocoding'`, `'NearPoi'`, ...).
* @return {Boolean}
*/
bemap.GeoServerInfoResponse.prototype.hasService = function(serviceName) {
for (var i = 0; i < this.servicesInfo.length; i++) {
if (this.servicesInfo[i].getServiceName() === serviceName) return true;
}
return false;
};
/**
* `true` when the selected geoserver supports the named travel mode.
*
* info.supportsTransport(bemap.TransportMode.TRUCK) // true on 'here'
*
* @public
* @param {String} transportType
* @return {Boolean}
*/
bemap.GeoServerInfoResponse.prototype.supportsTransport = function(transportType) {
return this.transportTypes.indexOf(transportType) >= 0;
};
/**
* All limits attached to the named server-side service. Returns `[]` if none.
*
* info.getLimitsForService('BenomadNearPoiService')
*
* @public
* @param {String} serviceName Server-side bean name (e.g. `'BenomadNearPoiService'`).
* @return {Array.<bemap.GeoServerServiceLimit>}
*/
bemap.GeoServerInfoResponse.prototype.getLimitsForService = function(serviceName) {
return this.serviceLimits.filter(function(l) {
return l.getServiceName() === serviceName;
});
};
bemap.GeoServerInfoResponse.fromJson = function(json) {
if (!json) return new bemap.GeoServerInfoResponse();
var servicesInfo = Array.isArray(json.servicesInfo)
? json.servicesInfo.map(function(s) { return bemap.GeoServerServiceInfo.fromJson(s); })
: [];
var serviceLimits = Array.isArray(json.serviceLimits)
? json.serviceLimits.map(function(l) { return bemap.GeoServerServiceLimit.fromJson(l); })
: [];
return new bemap.GeoServerInfoResponse({
availableGeoServerNames: json.availableGeoServerNames || [],
globalCopyright: json.globalCopyright,
globalCopyrightUrl: json.globalCopyrightUrl,
globalSupplierTerms: json.globalSupplierTerms,
globalSupplierTermsUrl: json.globalSupplierTermsUrl,
transportTypes: json.transportTypes || [],
truckAttributes: json.truckAttributes === true,
servicesInfo: servicesInfo,
serviceLimits: serviceLimits
});
};