import { useMutation, useQueryClient } from "@tanstack/react-query";
// import { EditInventory } from "../schemas/inventory";
import { updateProductAction, createProductAction,deleteProductAction } 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) => updateProductAction(data),
    onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
    onError: (e) => console.error('Error:', e)
  })
  return mutation;
}

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