Source: bemap-services-v2/search/bemap-autocomplete-geocoding-request.js

/**
 * BeNomad BeMap JavaScript API - AutocompleteGeocodingRequest
 *
 * Typed request for `bemap.Autocomplete.autocomplete(request)` and
 * `bemap.GeoAutocomplete.autocomplete(request)`.
 *
 * Wire shape mirrors the BeMap server contract (cross-checked against
 * `bemap-flutter-api/lib/service/autocomplete/model/autocomplete_geocoding_request.dart`).
 * Endpoint: `POST service/geocoding/autocomplete/1.0`.
 *
 * Required wire fields: `language`, `place`.
 *
 * @since 1.5.0
 * @public
 * @constructor
 * @param {Object} [options]
 * @param {String} [options.place]                       Text typed by the user. Required at request time.
 * @param {String} [options.language='en']               Required server-side; defaults to 'en'.
 * @param {bemap.Coordinate} [options.coordinate]        Centre of the search area.
 * @param {bemap.BoundingBox} [options.boundingBox]      Restrict to a bbox.
 * @param {Number} [options.radius]                      Radius in metres.
 * @param {String} [options.countryCode]                 ISO country code filter.
 * @param {Boolean} [options.addressDetails]             Return structured PostalAddress per item.
 * @param {Boolean} [options.enableLocationId]
 * @param {Boolean} [options.enableEntrances]
 * @param {Boolean} [options.enableHighlights]
 * @param {Boolean} [options.enableCategories]
 * @param {Boolean} [options.enableFoodTypes]
 * @param {Boolean} [options.enableChains]
 * @param {Boolean} [options.enableReferences]
 * @param {String} [options.geoserver]
 * @param {Number} [options.switchIndex]
 */
bemap.AutocompleteGeocodingRequest = function(options) {
    var opts = options || {};

    this.place = opts.place || null;
    this.language = opts.language || null;
    this.coordinate = opts.coordinate || null;
    this.boundingBox = opts.boundingBox || null;
    this.radius = (typeof opts.radius === 'number') ? opts.radius : null;
    this.countryCode = opts.countryCode || null;
    this.addressDetails = (typeof opts.addressDetails === 'boolean') ? opts.addressDetails : null;
    this.enableLocationId = (typeof opts.enableLocationId === 'boolean') ? opts.enableLocationId : null;
    this.enableEntrances = (typeof opts.enableEntrances === 'boolean') ? opts.enableEntrances : null;
    this.enableHighlights = (typeof opts.enableHighlights === 'boolean') ? opts.enableHighlights : null;
    this.enableCategories = (typeof opts.enableCategories === 'boolean') ? opts.enableCategories : null;
    this.enableFoodTypes = (typeof opts.enableFoodTypes === 'boolean') ? opts.enableFoodTypes : null;
    this.enableChains = (typeof opts.enableChains === 'boolean') ? opts.enableChains : null;
    this.enableReferences = (typeof opts.enableReferences === 'boolean') ? opts.enableReferences : null;
    this.geoserver = opts.geoserver || null;
    this.switchIndex = (typeof opts.switchIndex === 'number') ? opts.switchIndex : null;
};

bemap.AutocompleteGeocodingRequest.prototype.setPlace = function(v) { this.place = v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setLanguage = function(v) { this.language = v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setCoordinate = function(v) { this.coordinate = v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setBoundingBox = function(v) { this.boundingBox = v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setRadius = function(v) { this.radius = v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setCountryCode = function(v) { this.countryCode = v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setAddressDetails = function(v) { this.addressDetails = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableHighlights = function(v) { this.enableHighlights = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableCategories = function(v) { this.enableCategories = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setGeoserver = function(g) { this.geoserver = g; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableLocationId = function(v) { this.enableLocationId = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableEntrances = function(v) { this.enableEntrances = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableFoodTypes = function(v) { this.enableFoodTypes = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableChains = function(v) { this.enableChains = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setEnableReferences = function(v) { this.enableReferences = !!v; return this; };
bemap.AutocompleteGeocodingRequest.prototype.setSwitchIndex = function(v) { this.switchIndex = (typeof v === 'number') ? v : null; return this; };

bemap.AutocompleteGeocodingRequest.prototype.toJson = function() {
    var body = {};
    body.place = this.place || '';
    body.language = this.language || 'en';
    if (this.coordinate) {
        body.coordinate = {
            lon: (typeof this.coordinate.getLon === 'function') ? this.coordinate.getLon() : this.coordinate.lon,
            lat: (typeof this.coordinate.getLat === 'function') ? this.coordinate.getLat() : this.coordinate.lat
        };
    }
    if (this.boundingBox) {
        // Wire key is lowercase `boundingbox` (server @JsonProperty), NOT boundingBox.
        body.boundingbox = {
            minLon: this.boundingBox.minLon,
            minLat: this.boundingBox.minLat,
            maxLon: this.boundingBox.maxLon,
            maxLat: this.boundingBox.maxLat
        };
    }
    if (this.radius !== null) body.radius = this.radius;
    if (this.countryCode) body.countryCode = this.countryCode;
    if (this.addressDetails !== null) body.addressDetails = this.addressDetails;
    // The server expects the short `en*` wire keys (@JsonProperty, no aliases) —
    // emitting the long enableXxx names silently drops these flags.
    if (this.enableLocationId !== null) body.enLocId = this.enableLocationId;
    if (this.enableEntrances !== null) body.enEntrances = this.enableEntrances;
    if (this.enableHighlights !== null) body.enHighlights = this.enableHighlights;
    if (this.enableCategories !== null) body.enCategories = this.enableCategories;
    if (this.enableFoodTypes !== null) body.enFoodTypes = this.enableFoodTypes;
    if (this.enableChains !== null) body.enChains = this.enableChains;
    if (this.enableReferences !== null) body.enReferences = this.enableReferences;
    if (this.geoserver) body.geoserver = this.geoserver;
    if (this.switchIndex !== null) body.switchIndex = this.switchIndex;
    return body;
};