import { useMutation } from "@tanstack/react-query";

import { QueryKeys } from "../constants/query-keys";
import { OrdersService, ShipmentOrdersService } from "../services/api";

export function useInvoice() {
  //

  const generateOrderInvoiceAPI = useMutation({
    mutationKey: [QueryKeys.invoices.GENERATE_INVOICES],
    mutationFn: ({ orderId }: { orderId: string }) =>
      OrdersService.ordersControllerGetOrderInvoice(orderId),
    // onMutate: () => setLoading(true),
    onSuccess: async () => {},
    onError: () => {},
  });

  const generateCreditNoteInvoiceAPI = useMutation({
    mutationKey: [QueryKeys.invoices.GENERATE_INVOICES],
    mutationFn: ({ creditNote, type }: { creditNote: string; type: string }) =>
      OrdersService.ordersControllerGetCreditNoteInvoice(creditNote, type),
    // onMutate: () => setLoading(true),
    onSuccess: async () => {},
    onError: () => {},
  });

  const generateShippingOrderInvoiceAPI = useMutation({
    mutationKey: [QueryKeys.invoices.GENERATE_SHIPPING_INVOICES],
    mutationFn: ({ orderId }: { orderId: string }) =>
      ShipmentOrdersService.shippingOrdersControllerGetOrderInvoice(orderId),
    // onMutate: () => setLoading(true),
    onSuccess: async () => {},
    onError: () => {},
  });

  return {
    generateOrderInvoiceAPI,
    generateShippingOrderInvoiceAPI,
    generateCreditNoteInvoiceAPI,
  };
}
