import { getPayload } from 'payload'
import config from '@/payload.config'
import { Event } from '@/payload-types'

/**
 * Fetch a single event by ID
 */
export async function fetchEventById(
  id: string,
  draft: boolean = false,
): Promise<Event | undefined> {
  try {
    const payload = await getPayload({ config })
    return await payload.findByID({ collection: 'event', id, draft })
  } catch {
    return undefined
  }
}
