// src/collections/ServiceCategories.ts

import type { CollectionConfig } from 'payload'
import { authenticatedOnly, tenantScopedPublicRead } from '../lib/tenantAccess'

/**
 * ServiceCategories Collection
 *
 * Kategorien für Dienstleistungen/Services.
 * Ermöglicht Gruppierung und Filterung von Services.
 * Tenant-scoped für Multi-Tenant-Betrieb.
 */
export const ServiceCategories: CollectionConfig = {
  slug: 'service-categories',
  admin: {
    useAsTitle: 'name',
    group: 'Content',
    defaultColumns: ['name', 'slug', 'order', 'isActive'],
    description: 'Kategorien für Leistungen/Services',
  },
  access: {
    read: tenantScopedPublicRead,
    create: authenticatedOnly,
    update: authenticatedOnly,
    delete: authenticatedOnly,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      required: true,
      label: 'Name',
      localized: true,
      admin: {
        description: 'z.B. "Pflege", "Beratung", "Schulung"',
      },
    },
    {
      name: 'slug',
      type: 'text',
      required: true,
      label: 'Slug',
      unique: false,
      admin: {
        description: 'URL-freundlicher Name (z.B. "pflege", "beratung")',
      },
    },
    {
      name: 'description',
      type: 'textarea',
      label: 'Beschreibung',
      localized: true,
      admin: {
        description: 'Kurze Beschreibung der Kategorie',
      },
    },
    {
      name: 'icon',
      type: 'text',
      label: 'Icon',
      admin: {
        description: 'Icon-Name (z.B. "heart", "users", "book")',
      },
    },
    {
      name: 'image',
      type: 'upload',
      relationTo: 'media',
      label: 'Bild',
      admin: {
        description: 'Optionales Kategorie-Bild',
      },
    },
    {
      name: 'color',
      type: 'text',
      label: 'Farbe',
      admin: {
        description: 'Akzentfarbe für die Kategorie (z.B. "#3B82F6")',
      },
    },
    {
      name: 'isActive',
      type: 'checkbox',
      defaultValue: true,
      label: 'Aktiv',
      admin: {
        position: 'sidebar',
      },
    },
    {
      name: 'order',
      type: 'number',
      defaultValue: 0,
      label: 'Sortierung',
      admin: {
        position: 'sidebar',
        description: 'Niedrigere Zahlen werden zuerst angezeigt',
      },
    },
  ],
}
