const path = require('path');

const skeletonsPath = path.join(__dirname, 'skeletons');
const version = require(path.join(__dirname, '../package.json')).version;

module.exports.targetPath = path.resolve(process.cwd());
module.exports.skeletonsPath = skeletonsPath;

module.exports.angularBasePath = path.join(skeletonsPath, '_angular/base');
module.exports.angularBaseMobilePath = path.join(skeletonsPath, '_angular/base-mobile');

module.exports.webMavenPath = path.join(skeletonsPath, 'web-maven');
module.exports.webSpringBootPath = path.join(skeletonsPath, 'web-spring-boot');

module.exports.webPhpStarterRepo = 'webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-php-starter.git'
module.exports.webSymfonyPath = path.join(skeletonsPath, 'web-symfony');

module.exports.optionsPath = {
    "openid-jwt": path.join(skeletonsPath, '_angular/options/openid-jwt'),
    "ecl-ec": path.join(skeletonsPath, '_angular/options/ecl-ec'),
    "ecl-eu": path.join(skeletonsPath, '_angular/options/ecl-eu'),
    "ecl-openid-jwt": path.join(skeletonsPath, '_angular/options/merged-ecl-openid-jwt'),
};

module.exports.version = version;


module.exports.parseInputConfig = (inputConfig) => {

  if (!inputConfig) {
    return;
  }

  const configArray = inputConfig.split(',').map(item => {
    const x = item.split(':');

    var value = x[1];

    // treating text to boolean values : f.e. : npmInstall=true
    if (value === 'true') {
      value = true;
    }
    if (value === 'false') {
      value = false;
    }

    // treating string array values : f.e. : appFeatures=feature1_feature2_feature3
    if (typeof value === 'string' && value.indexOf('_')) {
      value = value.split('_');
    }

    return { [x[0]]: value };
  });

  return Object.assign({}, ...configArray);
}
