"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

function _bluebird() {
  const data = require("bluebird");

  _bluebird = function () {
    return data;
  };

  return data;
}

function _uidNumber() {
  const data = _interopRequireDefault(require("uid-number"));

  _uidNumber = function () {
    return data;
  };

  return data;
}

function _logger() {
  const data = _interopRequireDefault(require("../logger/logger"));

  _logger = function () {
    return data;
  };

  return data;
}

function _generalError() {
  const data = _interopRequireDefault(require("../error/general-error"));

  _generalError = function () {
    return data;
  };

  return data;
}

var _default =
/*#__PURE__*/
function () {
  var _resolveGroupId = (0, _bluebird().coroutine)(function* (groupName) {
    return new Promise((resolve, reject) => {
      (0, _uidNumber().default)(null, groupName, (err, uid, gid) => {
        if (err) {
          _logger().default.error(err);

          if (err.message.includes('EPERM')) {
            return reject(new (_generalError().default)(`unable to resolve group id of "${groupName}", current user does not have sufficient permissions`));
          }

          if (err.message.includes('group id does not exist')) {
            return reject(new (_generalError().default)(`unable to resolve group id of "${groupName}", the group does not exist`));
          }

          return reject(new (_generalError().default)(`unable to resolve group id of "${groupName}", got an error ${err.message}`));
        } // on Windows it'll always be null


        return resolve(gid);
      });
    });
  });

  function resolveGroupId(_x) {
    return _resolveGroupId.apply(this, arguments);
  }

  return resolveGroupId;
}();

exports.default = _default;