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

export const ContactPerson: CollectionConfig = {
  slug: 'contactPerson',
  labels: {
    singular: {
      de: 'Ansprechpartner'
    },
    plural: {
      de: "Ansprechpartner"
    }
  },
  fields: [
    {
      name: 'photo',
      type: 'upload',
      relationTo: 'media',
    },
    {
      name: 'name',
      type: 'text',
      required: true,
      label: {
        de: "Name"
      }
    },
    {
      name: 'role',
      type: 'text',
      label: {
        de: 'Funktion',
      },
    },
    {
      name: 'email',
      type: 'email',
    },
    {
      name: 'telephone',
      type: 'text',
      label: {
        de: 'Telefon'
      }
    }
  ],
  admin: {
    useAsTitle: "name",
    hidden: hide
  },
  access: {
    read: () => true,
    create: isAdminOrEmployee(),
    update: isAdminOrEmployee(),
    delete: isAdminOrEmployee(),
  },
}