import { CollectionConfig } from 'payload'
import { hide, isAdminOrEmployee } from '@/collections/access/admin'
import { siteConfig } from '@/config/site'

export const Magazine: CollectionConfig = {
  slug: 'magazine',
  labels: {
    singular: {
      de: `${siteConfig.magazineName} Ausgabe`,
    },
    plural: {
      de: `${siteConfig.magazineName} Ausgaben`,
    },
  },
  fields: [
    {
      name: 'cover',
      type: 'upload',
      relationTo: 'media',
      label: {
        de: 'Titelblatt'
      },
      required: true
    },
    {
      name: 'document',
      type: 'upload',
      relationTo: 'documents',
      label: {
        de: 'PDF-dokument'
      },
      required: true,
    },
    {
      name: 'date',
      type: 'date',
      label: {
        de: 'Datum'
      },
      required: true
    }
  ],
  admin: {
    hidden: hide
  },
  access: {
    read: () => true,
    update: isAdminOrEmployee(),
    delete: isAdminOrEmployee()
  },
}