import { CollectionConfig } from 'payload'
import { revalidateTag } from 'next/cache'
import { hide, isAdminOrEmployee } from '@/collections/access/admin'

export const Prayers: CollectionConfig = {
  slug: 'prayers',
  labels: {
    singular: {
      de: 'Stoßgebet',
    },
    plural: {
      de: 'Stoßgebete',
    },
  },
  fields: [
    {
      name: 'text',
      type: 'text',
      required: true,
      label: {
        de: 'Gebet',
      },
    },
  ],
  admin: {
    useAsTitle: 'text',
    hidden: hide
  },
  access: {
    read: () => true,
    create: isAdminOrEmployee(),
    update: isAdminOrEmployee(),
    delete: isAdminOrEmployee(),
  },
  hooks: {
    afterChange: [() => revalidateTag('prayers')],
    afterDelete: [() => revalidateTag('prayers')],
  },
}
