import { produce } from 'immer';
import { isValidUuid } from '../utils/isValidUuid';
const sanitiseFileId = draft => {
  const {
    fileId
  } = draft.attributes.fileAttributes;
  draft.attributes.fileAttributes.fileId = fileId === 'external-image' || isValidUuid(fileId) ? fileId : 'INVALID_FILE_ID';
};
const hasFileAttributesWithFileId = payload => '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 const sanitiseAnalyticsPayload = payload => hasFileAttributesWithFileId(payload) ? produce(payload, sanitiseFileId) : payload;