"use client"

import { useMutation, useQueryClient } from "@tanstack/react-query"
import { apiClient } from "@/lib/api/client"

export function useUpdateUserAvatar() {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: (avatarUrl: string) =>
      apiClient.put<{ avatar_url: string }>("/users/me/avatar", { avatar_url: avatarUrl }),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["current-user"] })
    },
  })
}

export function useDeleteUserAvatar() {
  const queryClient = useQueryClient()

  return useMutation({
    mutationFn: () => apiClient.delete("/users/me/avatar"),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["current-user"] })
    },
  })
}
