import {MeResponseSchema, type PublicUser} from '@crumbs/core/schemas'

import {blobEndpoint} from '@/lib/blob-endpoint'

// the avatar endpoint is singular (one per account): no id in the path, and
// the picker square-crops
const avatar = blobEndpoint({
  path: () => '/auth/avatar',
  schema: MeResponseSchema,
  unwrap: ({user}) => user,
  maxEdge: 1024,
  crop: 'square',
})

export const pickAvatarImage = avatar.pick
export const uploadAvatar = (uri: string): Promise<PublicUser> =>
  avatar.upload('', uri)
export const deleteAvatar = (): Promise<PublicUser> =>
  avatar.remove('')
