import {reencodeWebp, type ProcessedImage} from './image'

const AVATAR_SIZE = 512
const MAX_INPUT_BYTES = 6 * 1024 * 1024

export {InvalidImageError} from './image'

// re-encode to a square webp — neutralizes crafted payloads, strips exif,
// normalizes size
export const processAvatar = (
  input: Uint8Array,
): Promise<ProcessedImage> =>
  reencodeWebp(input, {
    width: AVATAR_SIZE,
    height: AVATAR_SIZE,
    fit: 'cover',
    maxInputBytes: MAX_INPUT_BYTES,
  })

export const avatarKey = (userId: string, hash: string) =>
  `avatars/${userId}/${hash}.webp`
