import { CollectionConfig, Field } from "payload";

const WorkoutExercices: Field[] = [
  {
    type: 'row',
    fields: [
      {
        name: 'exercise',
        type: 'relationship',
        relationTo: 'exercises',
        hasMany: false,
        admin: {
          width: '25%',
        },

      },
      {
        name: 'reps',
        type: 'number',
        min: 1,
        admin: {
          width: '25%',
        },

      },
      {
        name: 'sets',
        type: 'number',
        min: 1,
        admin: {
          width: '25%',
        },
      },
      {
        name: 'restMinutesAfterSet',
        type: 'number',
        admin: {
          width: '25%',
        },
      },
    ]
  }
]

export const WorkoutTypes: CollectionConfig = {
  slug: 'workoutTypes',
  admin: {
    useAsTitle: 'name',
    group: 'Exercise',
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      unique: true,
      admin: {
        description: 'Strength, Cardio, etc...',
      },
    },
    {
      name: 'description',
      type: 'textarea',
    },
  ],
}

export const Workouts: CollectionConfig = {
  slug: 'workouts',
  admin: {
    useAsTitle: 'name',
    group: 'Exercise',
  },
  fields: [
    {
      name: 'name',
      type: 'text',
      unique: true,
    },
    {
      name: 'type',
      type: 'relationship',
      relationTo: 'workoutTypes',
      hasMany: true,
    },
    {
      name: 'difficulty',
      type: 'number',
      max: 10,
    },
    {
      name: 'description',
      type: 'textarea',
    },
    {
      name: 'durationMinutes',
      type: 'number',
    },
    {
      name: 'exercises',
      type: 'array',
      fields: WorkoutExercices
    }
  ],
}
