text: const { Schema, Types, model } = require("mongoose");
  const Reaction = require("./Reaction");
  const moment = require("moment");
  
  const thoughtSchema = new Schema(
    {
      thoughtText: {
        type: Schema.Types.String,
        required: true,
        minlength: 1,
        maxlength: 280,
      },
      createdAt: {
        type: Date,
        default: Date.now,
        get: (createdAtVal) =>
          moment(createdAtVal).format("MMM DD, YYYY [at] hh:mm a"),
      },
      username: {
        type: Schema.Types.String,
        required: true,
      },
      reactions: [Reaction],
    },
    {
      toJSON: {
        virtuals: true,
        getters: true
      },
      id: false,
    }
  );
  
  // Virtual called reactionCount that retrieves the length of the thought's reactions array field on query
  
  thoughtSchema.virtual("reactionCount").get(function () {
    return this.reactions.length;
  });
  
  const Thought = model("thought", thoughtSchema);
  module.exports = Thought;
  