import { Search } from '@/payload-types'

export function getSearchResultUrl(doc: Search['doc']): string | null {
  if (!doc || typeof doc.value === 'string') return null

  switch (doc.relationTo) {
    case 'pages':
      return doc.value.slug ? `/${doc.value.slug}` : null
    case 'blog':
      return `/blog/${doc.value.id}`
    case 'parish':
      return doc.value.slug ? `/gemeinde/${doc.value.slug}` : null
    case 'event':
      return `/veranstaltungen/${doc.value.id}`
    case 'group':
      return doc.value.slug ? `/gruppe/${doc.value.slug}` : null
    default:
      return null
  }
}
