text: const mongoose = require("mongoose");
  
  const Schema = mongoose.Schema;
  
  const workoutSchema = new Schema(
    {
      day: {
        type: Date,
        default: Date.now,
      },
      exercises: [
        {
          name: {
            type: String,
            trim: true,
            required: "Enter an Exercise Name ",
          },
          type: {
            type: String,
            trim: true,
            required: "Enter an Exercise Type",
          },
          distance: {
            type: Number,
          },
          weight: {
            type: Number,
          },
          duration: {
            type: Number,
          },
          sets: {
            type: Number,
          },
          reps: {
            type: Number,
          },
        },
       
      ],
    },
    {
      toJSON: { virtuals: true },
    },
  );
  
  workoutSchema.virtual("totalDuration").get(function () {
    return this.exercises.reduce((total, exercise)=>{
        return total + exercise.duration;
    },0)
  });
  
  const Workout = mongoose.model("Workout", workoutSchema);
  
  module.exports = Workout;
  