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

export const Employees: CollectionConfig = {
  slug: 'employees',
  labels: {
    singular: {
      de: 'Mitarbeiter',
    },
    plural: 'Mitarbeiter',
  },
  fields: [
    {
      name: 'photo',
      label: {
        de: 'Foto',
      },
      type: 'upload',
      relationTo: 'media',
    },
    {
      name: 'name',
      type: 'text',
      label: {
        de: 'Name',
      },
      required: true,
    },
    {
      name: 'occupation',
      type: 'text',
      label: {
        de: 'Tätigkeit',
      },
      required: true,
    },
    {
      name: 'email',
      type: 'email',
      label: {
        de: 'Email',
      },
    },
    {
      name: 'telephone',
      type: 'text',
      label: {
        de: 'Telefon',
      },
      required: false,
    },
  ],
  admin: {
    useAsTitle: 'name',
  },
  access: {
    read: () => true,
    create: isAdminOrEmployee(),
    update: isAdminOrEmployee(),
    delete: isAdminOrEmployee(),
  },
}
