text: const { Schema, model, Types } = require('mongoose');
  
  const ReactionSchema = new Schema(
      {
          reactionId: {
              type: Schema.Types.ObjectId,
              default: () => new Types.ObjectId
          },
          reactionBody: {
              type: String,
              required: true,
              min: 1,
              max: 280
          },
          username: {
              type: String,
              required: true
          },
          createdAt: {
              type: Date,
              default: Date.now
          }
      },
      {
          toJSON: {
              getters: true
          },
      }
  );
  
  
  
  const ThoughtSchema = new Schema(
      {
          thoughtText: {
              type: String,
              required: true,
              min: 1,
              max: 280
          },
          createdAt: {
              type: Date,
              default: Date.now
          },
          username: {
              type: String,
              required: true
          },
          reactions: [ReactionSchema]
      },
      {
          toJSON: {
              virtuals: true,
              getters: true
          },
  
          // prevents virtuals from creating duplicate of _id as `id`
          id: false
      },
  );
  
  ThoughtSchema.virtual('reactionCount').get(function () {
      return this.reactions.length;
  })
  
  const Thought = model('Thought', ThoughtSchema);
  
  module.exports = Thought;
  
  