"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.sanitiseAnalyticsPayload = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _immer = require("immer");
var _isValidUuid = require("../utils/isValidUuid");
var sanitiseFileId = function sanitiseFileId(draft) {
  var fileId = draft.attributes.fileAttributes.fileId;
  draft.attributes.fileAttributes.fileId = fileId === 'external-image' || (0, _isValidUuid.isValidUuid)(fileId) ? fileId : 'INVALID_FILE_ID';
};
var hasFileAttributesWithFileId = function hasFileAttributesWithFileId(payload) {
  return 'attributes' in payload && !!payload.attributes && (0, _typeof2.default)(payload.attributes) === 'object' && 'fileAttributes' in payload.attributes && !!payload.attributes.fileAttributes && (0, _typeof2.default)(payload.attributes.fileAttributes) === 'object' && 'fileId' in payload.attributes.fileAttributes && typeof payload.attributes.fileAttributes.fileId === 'string';
};
var sanitiseAnalyticsPayload = exports.sanitiseAnalyticsPayload = function sanitiseAnalyticsPayload(payload) {
  return hasFileAttributesWithFileId(payload) ? (0, _immer.produce)(payload, sanitiseFileId) : payload;
};