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

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

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