Source: bemap-services-v2/ev/bemap-ev-vehicle.js

/**
 * BeNomad BeMap JavaScript API - EvVehicle (v1.5)
 *
 * Single vehicle entry from `GET service/vehicle/1.1/findvehicles`. Mirrors
 * the v1.1 Java DTO at
 * `bemap_idea/.../service/v1_1_0/model/vehicle/VehicleInfo.java`. Every
 * field below comes verbatim from the plaintext wire response — no parsing
 * of formatted strings, no AES decryption.
 *
 * @public
 * @constructor
 * @param {Object} options Parsed JSON entry from the server.
 */
bemap.EvVehicle = function(options) {
    var opts = options || {};

    // Core identity
    this.key = opts.key || null;
    this.brandId = opts.brandId || null;
    this.brandName = opts.brandName || null;
    this.name = opts.name || null;
    this.year = opts.year || null;
    this.variant = opts.variant || null;
    this.motorType = opts.motorType || null;

    // Charging / battery (plaintext, no decryption needed)
    this.batteryName = opts.batteryName || null;
    this.chargerPowerAcSinglePhase = (typeof opts.chargerPowerAcSinglePhase === 'number') ? opts.chargerPowerAcSinglePhase : null;
    this.chargerPowerAcThreePhases = (typeof opts.chargerPowerAcThreePhases === 'number') ? opts.chargerPowerAcThreePhases : null;
    this.chargerPowerDC = (typeof opts.chargerPowerDC === 'number') ? opts.chargerPowerDC : null;
    this.connectorTypes = Array.isArray(opts.connectorTypes) ? opts.connectorTypes.slice() : [];

    // v1.1 enrichment
    this.transportType = opts.transportType || null;
    this.height = (typeof opts.height === 'number') ? opts.height : null;
    this.width = (typeof opts.width === 'number') ? opts.width : null;
    this.length = (typeof opts.length === 'number') ? opts.length : null;
    this.maxWeight = (typeof opts.maxWeight === 'number') ? opts.maxWeight : null;
    this.maxWeightPerAxle = (typeof opts.maxWeightPerAxle === 'number') ? opts.maxWeightPerAxle : null;
    this.wltp = opts.wltp || null;
    this.consumptionInWhPerKm = (typeof opts.consumptionInWhPerKm === 'number') ? opts.consumptionInWhPerKm : null;
    this.plugAndAutoCharge = opts.plugAndAutoCharge || null;

    // Encrypted datasheet (base64 AES blob — exposed opaque; customers
    // who need the structured datasheet implement decryption with the
    // shared secret themselves).
    this.encDatasheet = opts.encDatasheet || null;
};

bemap.EvVehicle.prototype.getKey = function() { return this.key; };
bemap.EvVehicle.prototype.getBrandId = function() { return this.brandId; };
bemap.EvVehicle.prototype.getBrandName = function() { return this.brandName; };
bemap.EvVehicle.prototype.getName = function() { return this.name; };
bemap.EvVehicle.prototype.getYear = function() { return this.year; };
bemap.EvVehicle.prototype.getVariant = function() { return this.variant; };
bemap.EvVehicle.prototype.getMotorType = function() { return this.motorType; };

/**
 * Battery capacity in kWh, parsed from the server's `batteryName` field
 * (which arrives as a numeric-looking string like `"66"` or `"49"`).
 * Returns `null` when the field isn't numeric.
 * @public
 * @return {Number|null}
 */
bemap.EvVehicle.prototype.getBatteryCapacity = function() {
    if (!this.batteryName) return null;
    var n = parseFloat(this.batteryName);
    return isNaN(n) ? null : n;
};
bemap.EvVehicle.prototype.getBatteryName = function() { return this.batteryName; };
bemap.EvVehicle.prototype.getMaxChargingPowerAcSinglePhase = function() { return this.chargerPowerAcSinglePhase; };
bemap.EvVehicle.prototype.getMaxChargingPowerAcThreePhases = function() { return this.chargerPowerAcThreePhases; };
bemap.EvVehicle.prototype.getMaxChargingPowerDc = function() { return this.chargerPowerDC; };
bemap.EvVehicle.prototype.getConnectorTypes = function() { return this.connectorTypes; };

bemap.EvVehicle.prototype.getTransportType = function() { return this.transportType; };

/**
 * Vehicle dimensions in centimetres, or `null` when not provided.
 * @public
 * @return {{height: Number, width: Number, length: Number}|null}
 */
bemap.EvVehicle.prototype.getDimensions = function() {
    if (this.height === null && this.width === null && this.length === null) return null;
    return { height: this.height, width: this.width, length: this.length };
};
bemap.EvVehicle.prototype.getMaxWeight = function() { return this.maxWeight; };
bemap.EvVehicle.prototype.getMaxWeightPerAxle = function() { return this.maxWeightPerAxle; };
bemap.EvVehicle.prototype.getWltp = function() { return this.wltp; };
bemap.EvVehicle.prototype.getConsumptionInWhPerKm = function() { return this.consumptionInWhPerKm; };
bemap.EvVehicle.prototype.getPlugAndAutoCharge = function() { return this.plugAndAutoCharge; };

/**
 * Base64-encoded AES-encrypted datasheet blob, or `null` when the request
 * did not set `enableDatasheet: true` or the user lacks `ROLE_VEHICLE_DATASHEET`.
 * Decryption uses AES/ECB/PKCS5Padding with a shared key — out of scope
 * for this library; document the contract for power users.
 * @public
 * @return {String|null}
 */
bemap.EvVehicle.prototype.getDatasheet = function() { return this.encDatasheet; };

/**
 * Human-readable single-line summary built from the typed fields.
 * Useful for `<option>` labels in vehicle pickers.
 * @public
 * @return {String}
 */
bemap.EvVehicle.prototype.getDisplayLabel = function() {
    var bits = [];
    if (this.name) bits.push(this.name);
    if (this.variant) bits.push(this.variant);
    if (this.year) bits.push('(' + this.year + ')');
    var head = bits.join(' ');
    var specs = [];
    if (this.batteryName) specs.push(this.batteryName + ' kWh');
    if (this.chargerPowerDC) specs.push('DC:' + this.chargerPowerDC + 'kW');
    if (this.chargerPowerAcThreePhases) specs.push('AC3:' + this.chargerPowerAcThreePhases + 'kW');
    else if (this.chargerPowerAcSinglePhase) specs.push('AC1:' + this.chargerPowerAcSinglePhase + 'kW');
    return head + (specs.length ? ' ' + specs.join(' ') : '');
};

/**
 * Parse a raw vehicle JSON entry into an `EvVehicle`.
 * @public
 * @param {Object} json
 * @return {bemap.EvVehicle}
 */
bemap.EvVehicle.fromJson = function(json) {
    return new bemap.EvVehicle(json || {});
};