import type { CollectionConfig } from 'payload'
import { auditUserAfterChange, auditUserAfterDelete } from '../hooks/auditUserChanges'
import {
  auditAfterLogin,
  auditAfterLogout,
  auditAfterForgotPassword,
} from '../hooks/auditAuthEvents'

export const Users: CollectionConfig = {
  slug: 'users',
  admin: {
    useAsTitle: 'email',
  },
  auth: true,
  hooks: {
    afterChange: [auditUserAfterChange],
    afterDelete: [auditUserAfterDelete],
    afterLogin: [auditAfterLogin],
    afterLogout: [auditAfterLogout],
    afterForgotPassword: [auditAfterForgotPassword],
  },
  fields: [
    {
      name: 'isSuperAdmin',
      type: 'checkbox',
      label: 'Super Admin',
      defaultValue: false,
      admin: {
        description: 'Super Admins haben Zugriff auf alle Tenants und können neue Tenants erstellen.',
        position: 'sidebar',
      },
    },
  ],
}
