'use strict';

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

var _fields = require('./fields');

var _fields2 = _interopRequireDefault(_fields);

var _forms = require('./forms');

var _forms2 = _interopRequireDefault(_forms);

var _messages = require('./messages');

var _messages2 = _interopRequireDefault(_messages);

var _serviceConfig = require('./serviceConfig');

var _serviceConfig2 = _interopRequireDefault(_serviceConfig);

var _title = require('./title');

var _title2 = _interopRequireDefault(_title);

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

exports.default = function () {
  return function (pluginContext) {
    return {
      recordTypes: {
        blob: {
          messages: _messages2.default,
          serviceConfig: _serviceConfig2.default,
          content: {
            full: {
              subresource: 'original'
            },
            preview: {
              subresource: 'derivativeThumbnail'
            }
          },
          fields: (0, _fields2.default)(pluginContext),
          forms: (0, _forms2.default)(pluginContext),
          // Override the default cspace-client requestConfig, since we need to
          // do a multipart/form-data file upload instead of sending the usual
          // JSON payload.
          requestConfig: function requestConfig(data) {
            var value = data.getIn(['document', 'ns2:blobs_common', 'file']);

            if (value instanceof Array) {
              if (value.length > 0) {
                return {
                  type: 'multipart/form-data',
                  data: {
                    document: null,
                    file: value[0]
                  }
                };
              }
            } else if (typeof value === 'string') {
              return {
                params: {
                  blobUri: value
                }
              };
            }

            return undefined;
          },
          title: (0, _title2.default)(pluginContext)
        }
      }
    };
  };
};