import { useDataSource, useQueryKey } from "@erp/core/hooks";
import { ListCustomersResponseDTO } from "@erp/customer-invoices/common";
import { useQuery } from "@tanstack/react-query";

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

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

      return customers as ListCustomersResponseDTO;
    },
  });
};
