import { CollectionConfig } from 'payload'
import { isAdminOrEmployee } from '@/collections/access/admin'

export const Announcements: CollectionConfig = {
  slug: 'announcement',
  labels: {
    singular: {
      de: 'Vermeldung'
    },
    plural: {
      de: 'Vermeldungen'
    }
  },
  fields: [
    {
      name: 'date',
      type: 'date',
      required: true,
      label: {
        de: 'Datum'
      }
    },
    {
      name: 'parish',
      type: "relationship",
      relationTo: 'parish',
      required: true,
      hasMany: true,
      label: {
        de: "Gemeinde"
      },
      admin: {
        allowCreate: false,
        allowEdit: false
      }
    },
    {
      name: 'document',
      label: {
        de: "PDF-Dokument"
      },
      type: 'upload',
      relationTo: 'documents',
      required: true
    }
  ],
  access: {
    read: () => true,
    create: isAdminOrEmployee(),
    update: isAdminOrEmployee(),
    delete: isAdminOrEmployee(),
  }
}