import { useDataSource, useQueryKey } from "@erp/core/hooks";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { CreateCustomerInvoiceRequestDTO } from "../../common/dto";

export const useCreateCustomerInvoiceMutation = () => {
  const queryClient = useQueryClient();
  const dataSource = useDataSource();
  const keys = useQueryKey();

  return useMutation<
    CreateCustomerInvoiceRequestDTO,
    Error,
    Partial<CreateCustomerInvoiceRequestDTO>
  >({
    mutationFn: (data) => {
      console.log(data);
      return dataSource.createOne("customer-invoices", data);
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["customer-invoices"] });
    },
  });
};
