import _typeof from "@babel/runtime/helpers/typeof";
import { produce } from 'immer';
import { isValidUuid } from '../utils/isValidUuid';
var sanitiseFileId = function sanitiseFileId(draft) {
  var fileId = draft.attributes.fileAttributes.fileId;
  draft.attributes.fileAttributes.fileId = fileId === 'external-image' || isValidUuid(fileId) ? fileId : 'INVALID_FILE_ID';
};
var hasFileAttributesWithFileId = function hasFileAttributesWithFileId(payload) {
  return 'attributes' in payload && !!payload.attributes && _typeof(payload.attributes) === 'object' && 'fileAttributes' in payload.attributes && !!payload.attributes.fileAttributes && _typeof(payload.attributes.fileAttributes) === 'object' && 'fileId' in payload.attributes.fileAttributes && typeof payload.attributes.fileAttributes.fileId === 'string';
};
export var sanitiseAnalyticsPayload = function sanitiseAnalyticsPayload(payload) {
  return hasFileAttributesWithFileId(payload) ? produce(payload, sanitiseFileId) : payload;
};