import {useQuery} from "@tanstack/react-query";
import {ProductService} from "../../../client";

type Props = {
    clientId: number,
    page?: number,
    itemsPerPage?: number,
}
const useProductsList = (props: Props) => {
    const {clientId, page, itemsPerPage} = props;
    const {data, refetch} = useQuery({
        queryKey: ['getAllServices', clientId, page, itemsPerPage],
        queryFn: () => ProductService.getProductsByClientId({clientId, page, itemsPerPage})
    });
    const products = !data ? [] : data.products;
    const paginationInfo = data?.paginationInfo;
    return {products, paginationInfo, refetch}
}
export default useProductsList;