use crate::error::{ApiError, Result};

pub fn convert_to_webp(image_data: &[u8]) -> Result<Vec<u8>> {
    let img = image::load_from_memory(image_data)
        .map_err(|e| ApiError::ValidationError(format!("Invalid image format: {}", e)))?;
    
    let mut webp_data = Vec::new();
    let encoder = webp::Encoder::from_image(&img)
        .map_err(|e| ApiError::Internal(format!("Failed to create WebP encoder: {}", e)))?;
    
    let encoded = encoder.encode(80.0);
    webp_data.extend_from_slice(&*encoded);
    
    Ok(webp_data)
}