import { unstable_cache } from 'next/cache'
import { getPayload } from 'payload'
import config from '@/payload.config'

export const fetchPrayers = unstable_cache(
  async (): Promise<string[]> => {
    const payload = await getPayload({ config })
    const data = await payload.find({
      collection: 'prayers',
      limit: 0,
    })
    return data.docs.map((p) => p.text)
  },
  ['prayers'],
  { tags: ['prayers'] },
)
