import { infiniteQueryOptions } from '@tanstack/react-query'
import { getSelfCollections } from 'src/lib/api'
import { queryKeys } from './keys'

export const collectionQueries = {
  self: () =>
    infiniteQueryOptions({
      queryKey: queryKeys.collections.self(),
      queryFn: ({ pageParam }) => getSelfCollections({ pageParam }),
      initialPageParam: 1,
      staleTime: 5 * 60 * 1000,
      gcTime: 60 * 60 * 1000,
      getNextPageParam: (lastPage: any[], _allPages: any[], lastPageParam: number) => {
        if (lastPage.length === 0) return undefined
        return lastPageParam + 1
      },
      getPreviousPageParam: (
        _firstPage: any[],
        _allPages: any[],
        firstPageParam: number
      ) => {
        if (firstPageParam <= 1) return undefined
        return firstPageParam - 1
      },
    }),
}
