/**
* for manipulating overall config in to smaller configs for each component
* @module
*/
/**
* build the fuel and electric config
* @param {struct} skv_config
* @returns {struct}
*/
const fuelAndElectric = (skv_config) => {
const skv_return = {
total_miles: skv_config.total_miles,
ice_vat_percentage: skv_config.ice.vat_percentage,
elec_vat_percentage: skv_config.electric.vat_percentage,
};
// add any additional keys if they exist
skv_return.journey_miles = skv_config?.journey_miles;
// ICE vehicles
skv_return.ice_pp_litre = skv_config?.ice?.pp_litre;
skv_return.mpg = skv_config?.vehicle?.mpg;
// electric vehicles
skv_return.elec_pp_kwh = skv_config?.electric?.pp_kwh;
skv_return.battery_range_miles = skv_config?.vehicle?.battery_range_miles;
skv_return.battery_total_capacity_kwh = skv_config?.vehicle?.battery_total_capacity_kwh;
skv_return.battery_range_miles = skv_config?.vehicle?.battery_range_miles;
return skv_return;
};
/**
* work out which config to build
* @param {struct} skv_config
* @param {str_component_name}
* @returns {struct} built config
*/
const buildConfig = (skv_config, str_component_name) => {
if (str_component_name === 'fuel and electric') {
return fuelAndElectric(skv_config);
}
throw new Error('Unknown component name');
};
export {
buildConfig,
};