text: const mongoose = require("mongoose");
  const bcrypt = require("bcrypt");
  
  const UserSchema = new mongoose.Schema(
    {
      name: {
        type: String,
        minlength: [6, "Name must be atleast 6 characters"],
        required: [true, "Please provide a name"],
        trim: true,
      },
      email: {
        type: String,
        required: [true, "Please provide an email"],
        trim: true,
      },
      password: {
        type: String,
        required: [true, "Password is required"],
        trim: true,
        minlength: [6, "Password must be atleast 6 characters long"],
      },
    },
    { timestamps: true }
  );
  
  UserSchema.pre("save", async function () {
    const salt = await bcrypt.genSalt(10);
    this.password = await bcrypt.hash(this.password, salt);
  });
  
  UserSchema.methods.comparePassword = function (password) {
    return bcrypt.compareSync(password, this.password);
  };
  
  const User = mongoose.model("User", UserSchema);
  
  module.exports = User;
  