'use strict';

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

var _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

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

var createInvocationData = exports.createInvocationData = function createInvocationData(config, invocationDescriptor) {
  var recordType = invocationDescriptor.recordType,
      invocationCsid = invocationDescriptor.csid;


  var docType = (0, _get2.default)(config, ['recordTypes', recordType, 'serviceConfig', 'objectName']);

  var invocationContext = {
    docType: docType
  };

  if (invocationCsid === null || typeof invocationCsid === 'undefined') {
    invocationContext.mode = 'nocontext';
  } else if (Array.isArray(invocationCsid)) {
    invocationContext.mode = 'list';
    invocationContext.listCSIDs = { csid: invocationCsid };
  } else {
    invocationContext.mode = 'single';
    invocationContext.singleCSID = invocationCsid;
  }

  return {
    'ns2:invocationContext': Object.assign({
      '@xmlns:ns2': 'http://collectionspace.org/services/common/invocable'
    }, invocationContext)
  };
};

exports.default = {};