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

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