'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _stringFormat;

function _load_stringFormat() {
  return _stringFormat = _interopRequireDefault(require('string-format'));
}

var _constants;

function _load_constants() {
  return _constants = require('../../constants');
}

var _generalError;

function _load_generalError() {
  return _generalError = _interopRequireDefault(require('../../error/general-error'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var BitStructure = function () {
  function BitStructure(componentsDefaultDirectory, dependenciesDirectory, ejectedEnvsDirectory) {
    _classCallCheck(this, BitStructure);

    this.componentsDefaultDirectory = componentsDefaultDirectory || (_constants || _load_constants()).DEFAULT_COMPONENTES_DIR_PATH;
    this.dependenciesDirectory = dependenciesDirectory || (_constants || _load_constants()).DEFAULT_DEPENDENCIES_DIR_PATH;
    this.ejectedEnvsDirectory = ejectedEnvsDirectory || (_constants || _load_constants()).DEFAULT_EJECTED_ENVS_DIR_PATH;
  }

  _createClass(BitStructure, [{
    key: '_getComponentStructurePart',
    value: function _getComponentStructurePart(componentStructure, componentPart) {
      switch (componentPart) {
        case 'name':
          return 'name';
        case 'namespace':
          return 'box';
        case 'scope':
          return 'scope';
        case 'version':
          return 'version';
        default:
          throw new (_generalError || _load_generalError()).default(`the ${componentPart} part of the component structure
           ${componentStructure} is invalid, it must be one of the following: "name", "namespace", "scope" or "version" `);
      }
    }
  }, {
    key: 'dependenciesDirStructure',
    get: function get() {
      return this.dependenciesDirectory;
    }
  }, {
    key: 'ejectedEnvsDirStructure',
    get: function get() {
      return this.ejectedEnvsDirectory;
    }

    /**
     * Return only the static parts of the ejectedEnvs dir
     * Used for adding it to the ignore list
     */

  }, {
    key: 'staticEjectedEnvsDirStructure',
    get: function get() {
      var ejectedEnvsDirectory = this.ejectedEnvsDirectory;
      var staticEjectedEnvsDirectory = (0, (_stringFormat || _load_stringFormat()).default)(ejectedEnvsDirectory, { envType: '' });
      return staticEjectedEnvsDirectory;
    }
  }, {
    key: 'componentsDirStructure',
    get: function get() {
      var _this = this;

      var dirStructure = this.componentsDefaultDirectory;
      var staticParts = [];
      var dynamicParts = [];
      dirStructure.split('/').forEach(function (dir) {
        if (dir.startsWith('{') && dir.endsWith('}')) {
          // this is a variable
          var dirStripped = dir.replace(/[{}]/g, '');
          var componentPart = _this._getComponentStructurePart(dirStructure, dirStripped);
          dynamicParts.push(componentPart);
        } else {
          // todo: create a new exception class
          if (!(_ramda || _load_ramda()).default.isEmpty(dynamicParts)) {
            throw new (_generalError || _load_generalError()).default(`${dirStructure} is invalid, a static directory can not be after the dynamic part`);
          }
          staticParts.push(dir);
        }
      });

      return { staticParts, dynamicParts };
    }
  }]);

  return BitStructure;
}();

exports.default = BitStructure;