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

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

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