const { pick } = require('lodash');

export function mapResponses(presignedUrls, s3Responses, scanResponses) {
  const uploaded = scanResponses.copied.map((fileName) => {
    const file = presignedUrls.find((data) => !data.error && data.fileMetadata.name === fileName).fileMetadata;
    return { ...pick(file, ['_id', 'contentType', 'name', 'uploadDate']), originalName: file.originalname };
  });
  const error = [
    ...presignedUrls.filter((data) => data.error),
    ...s3Responses.filter((data) => data.error).map((data) => data.error),
    ...scanResponses.error,
    ...scanResponses.quarantined,
  ];
  return { uploaded, error };
}

export default {
  mapResponses,
};
