"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.applyValuesToShema = applyValuesToShema;

function isObject(obj) {
  return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}

function applyValuesToShema(schemas, customOptions, processEnv) {
  const output = {};

  function decideValue(schema, key, customOptions) {
    const specificShema = schema[key];
    const correspondingValue = customOptions && customOptions[key];

    if (isObject(specificShema)) {
      if (typeof specificShema.cli === 'string') {
        var _ref, _processEnv$specificS;

        return (_ref = (_processEnv$specificS = processEnv[specificShema.cli]) !== null && _processEnv$specificS !== void 0 ? _processEnv$specificS : correspondingValue) !== null && _ref !== void 0 ? _ref : specificShema.value;
      }

      return applyValuesToShema(specificShema, correspondingValue, processEnv);
    }

    return correspondingValue !== null && correspondingValue !== void 0 ? correspondingValue : schema[key];
  } // console.log({schemas})


  Object.keys(schemas).forEach(key => {
    output[key] = decideValue(schemas, key, customOptions);
  });
  return output;
}