import type { CollectionConfig } from 'payload'

/**
 * YtBatches Collection - Angepasst an DB-Schema
 */
export const YtBatches: CollectionConfig = {
  slug: 'yt-batches',
  labels: {
    singular: 'Production Batch',
    plural: 'Production Batches',
  },
  admin: {
    group: 'YouTube',
    useAsTitle: 'name',
  },
  access: {
    read: () => true,
    create: ({ req }) => !!req.user,
    update: ({ req }) => !!req.user,
    delete: ({ req }) => !!req.user,
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      required: true,
      label: 'Name',
    },
    {
      name: 'channel',
      type: 'relationship',
      relationTo: 'youtube-channels',
      label: 'Channel',
    },
    {
      name: 'status',
      type: 'select',
      defaultValue: 'planning',
      label: 'Status',
      options: [
        { label: 'Planning', value: 'planning' },
        { label: 'Production', value: 'production' },
        { label: 'Published', value: 'published' },
      ],
    },
    // Production Period
    {
      name: 'productionPeriodStart',
      type: 'date',
      label: 'Production Start',
    },
    {
      name: 'productionPeriodEnd',
      type: 'date',
      label: 'Production End',
    },
    // Targets Group
    {
      name: 'targets',
      type: 'group',
      label: 'Targets',
      fields: [
        {
          name: 'shortsTarget',
          type: 'number',
          label: 'Shorts Target',
          defaultValue: 0,
        },
        {
          name: 'longformsTarget',
          type: 'number',
          label: 'Longforms Target',
          defaultValue: 0,
        },
        {
          name: 'totalTarget',
          type: 'number',
          label: 'Total Target',
          defaultValue: 0,
        },
        {
          name: 'bufferDays',
          type: 'number',
          label: 'Buffer Days',
          defaultValue: 0,
        },
      ],
    },
    // Progress Group
    {
      name: 'progress',
      type: 'group',
      label: 'Progress',
      fields: [
        {
          name: 'shortsCompleted',
          type: 'number',
          label: 'Shorts Completed',
          defaultValue: 0,
        },
        {
          name: 'longformsCompleted',
          type: 'number',
          label: 'Longforms Completed',
          defaultValue: 0,
        },
        {
          name: 'percentage',
          type: 'number',
          label: 'Percentage',
          defaultValue: 0,
        },
      ],
    },
    // Team Group
    {
      name: 'team',
      type: 'group',
      label: 'Team',
      fields: [
        {
          name: 'producer',
          type: 'relationship',
          relationTo: 'users',
          label: 'Producer',
        },
        {
          name: 'editor',
          type: 'relationship',
          relationTo: 'users',
          label: 'Editor',
        },
        {
          name: 'reviewer',
          type: 'relationship',
          relationTo: 'users',
          label: 'Reviewer',
        },
      ],
    },
  ],
  timestamps: true,
}
