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

// Obtener todos los clientes
export const useCustomersQuery = (params?: any) => {
  const dataSource = useDataSource();
  const keys = useQueryKey();

  return useQuery<CustomersListData>({
    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 CustomersListData;
    },
  });
};
