text: const { Model, DataTypes } = require('sequelize');
  const sequelize = require('../config/connection');
  const bcrypt = require('bcrypt');
  
  class User extends Model {
  
      //method to confirm and then encrypt password
      checkPassword(loginPw) {
          return bcrypt.compareSync(loginPw, this.password);
      }
  }
  
  User.init(
      {
          id: {
              type: DataTypes.INTEGER,
              allowNull: false,
              primaryKey: true,
              autoIncrement: true
          },
          username: {
              type: DataTypes.STRING,
              allowNull: false,
              validate: {
                  len: [5]
              }
          },
          password: {
              type: DataTypes.STRING,
              allowNull: false,
              validate: {
                  len: [5]
              }
          }
      },
      {
          hooks: {
              // set up beforeCreate lifecycle "hook" functionality
              async beforeCreate(newUserData) {
                newUserData.password = await bcrypt.hash(newUserData.password, 10);
                return newUserData;
              },
              // set up beforeUpdate lifecycle "hook" functionality
              async beforeUpdate(updatedUserData) {
                updatedUserData.password = await bcrypt.hash(updatedUserData.password, 10);
                return updatedUserData;
              }
          },
              sequelize,
              timestamp: false,
              freezeTableName: true,
              underscored: true,
              modelName: 'user'
      }
  );
  
  module.exports= User;
  