import { FastifyRequest } from 'fastify';

type FileMapperParams = {
  file: Express.Multer.File;
  req: FastifyRequest;
};

type FilesMapperParams = {
  files: Express.Multer.File[];
  req: FastifyRequest;
};

export const fileMapper = ({ file, req }: FileMapperParams): string => {
  const protocol = req.protocol;
  const host = req.headers.host;
  return `${protocol}://${host}/${file.path}`;
};

export const filesMapper = ({ files, req }: FilesMapperParams): string[] => {
  return files.map((file) => fileMapper({ file, req }));
};
