// File utility functions
const FileUtils = {
  getMimeType(filename) {
    const ext = filename.split('.').pop()?.toLowerCase();
    const map = {
      'png': 'image/png',
      'jpg': 'image/jpeg',
      'jpeg': 'image/jpeg',
      'webp': 'image/webp',
      'avif': 'image/avif'
    };
    return map[ext] || 'image/png';
  },

  isValidImageType(type) {
    return ['image/png', 'image/jpeg', 'image/webp', 'image/avif'].includes(type);
  },

  generateFilename(originalName, format) {
    const dotIndex = originalName.lastIndexOf('.');
    const baseName = dotIndex > 0 ? originalName.substring(0, dotIndex) : originalName;
    const extMap = {
      'image/webp': '.webp',
      'image/jpeg': '.jpg',
      'image/png': '.png',
      'image/avif': '.avif'
    };
    return `${baseName}${extMap[format] || '.png'}`;
  }
};
