import { useMutation, useQueryClient } from "@tanstack/react-query";
import { EditInventory } from "../schemas/inventory";
import { updateUserAction, createProductAction, updateUserAction2 } from "../actions/actions";

// Create mutation
export function useCreateProduct() {
  const queryClient = useQueryClient();
  const mutation = useMutation({
    mutationFn: (data: any) => createProductAction(data),
    onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
  })
  return mutation
}

// Update mutation
export function useUpdateProduct() {
  const queryClient = useQueryClient();
  const mutation = useMutation({
    // mutationFn: (data: EditInventory) => updateUserAction(data),
    mutationFn: (data: any) => updateUserAction2(data),
    onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
    onError: (e) => console.error('Error:', e)
  })
  return mutation;
}

// Delete mutation
// export function useDeleteUser() {
//   const queryClient = useQueryClient();
//   return useMutation({
//     mutationFn: (id: number) => deleteUserAction(id),
//     onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
//     onError: (e) => console.error('Error:', e)
//   })
// }