text: const { Schema, model } = require('mongoose');
  
  
  // User Schema
  const UserSchema = new Schema(
    {
        username: {
            type: String,
            unique: true,
            required: 'Please create a User Name',
            trim: true,
  
        },
        email: {
            type: String,
            required: 'Enter a valid email address',
            unique: true,
            validate: {
                validator(validEmail) {
                  //Regex method for confirming vaild email address
                  return /^([a-zA-Z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,6})(\.[a-z]{2,6})?$/.test(
                    validEmail
                  );
                },
                message: "Please enter a valid email address",
              },
        },
        thoughts: [{
            type: Schema.Types.ObjectId,
            ref: 'Thought'
        }],
        friends: [{
            type: Schema.Types.ObjectId,
            ref: 'User'
        }]
    },
    {
        toJSON: {
            virtuals: true,
            getters: true
        },
        id: false
    }
  );
  
  // friendCount Virtual
  UserSchema.virtual('friendCount').get(function () {
    return this.friends.length
  })
  
  
  const User = model('User', UserSchema)
  
  module.exports = User
  