'use es6';
import {Map} from 'immutable';
import Coordinate from '../../data/Coordinate';
import CoordinateBuilder from '../../data/builders/CoordinateBuilder';
import RideEstimatesSearch from '../RideEstimatesSearch';
export default class RideEstimatesSearchBuilder {
static build(json) {
let args = Map();
Iif (!('start' in json)) {
throw new TypeError('start is not in the search');
}
let startCoordinate = CoordinateBuilder.build(json['start']);
args = args.set('startCoordinate', startCoordinate);
Iif (!('end' in json)) {
throw new TypeError('end is not in the search');
}
let endCoordinate = CoordinateBuilder.build(json['end']);
args = args.set('endCoordinate', endCoordinate);
Iif (!('rideType' in json)) {
throw new TypeError('rideType is not in the search');
}
let rideType = RideEstimatesSearchBuilder.validateRideType(json['rideType']);
args = args.set('rideType', rideType);
return new RideEstimatesSearch(args);
}
static validateRideType(rideType) {
Iif (!Object.prototype.toString.call(rideType) === '[object String]') {
throw new TypeError('rideType is not a string');
}
const rideTypes = [
'lyft',
'lyft_line',
'lyft_plus',
];
Iif (rideTypes.indexOf(rideType) === -1) {
throw new RangeError('rideType must be either \'lyft\', \'lyft_line\', or \'lyft_plus\'');
}
return rideType;
}
}
|