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

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

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