import { useMutation, useQueryClient } from '@tanstack/react-query'
import { uploadAvatar } from '../api/profileApi'
import type { MeResponse, UploadAvatarPayload } from '../api/profileApi'

export function useUploadAvatar() {
  const queryClient = useQueryClient()
  return useMutation<MeResponse, unknown, UploadAvatarPayload>({
    mutationFn: uploadAvatar,
    onSuccess: (data) => {
      queryClient.setQueryData(['me'], data)
    },
  })
}
