/**
 * Process image paths and prepare them for database storage
 * @param {Array} images - Array of image objects with paths
 * @returns {Array} - Processed image objects with proper paths
 */
const processImagePaths = (images) => {
    if (!images || !Array.isArray(images)) {
      return [];
    }
  
    return images.map((image, index) => {
      // If the image is already a string (existing path), use it as is
      if (typeof image === 'string') {
        return {
          path: image,
          isPrimary: index === 0, // First image is primary by default
          displayOrder: index
        };
      }
  
      // If the image is an object from the upload middleware
      if (image.path || image.imagePath) {
        return {
          path: image.imagePath || image.path,
          isPrimary: image.isPrimary || index === 0,
          displayOrder: image.displayOrder || index
        };
      }
  
      // If the image is from the frontend (already has path field)
      return {
        path: image.path,
        isPrimary: image.isPrimary || index === 0,
        displayOrder: image.displayOrder || index
      };
    });
  };
  
  module.exports = {
    processImagePaths
  };