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

// Obtener todas las facturas
export const useCustomerInvoicesQuery = (params?: any) => {
  const dataSource = useDataSource();
  const keys = useQueryKey();

  return useQuery<ListCustomerInvoicesResponseDTO>({
    queryKey: keys().data().resource("customer-invoices").action("list").params(params).get(),
    queryFn: async (context) => {
      const { signal } = context;
      const invoices = await dataSource.getList("customer-invoices", {
        signal,
        ...params,
      });

      return invoices as ListCustomerInvoicesResponseDTO;
    },
  });
};
