const bcrypt = require('bcrypt');

module.exports = (sequelize, DataTypes) => {
  const Admin = sequelize.define('Admin', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    Name: {
      type: DataTypes.STRING(100),
      allowNull: false
    },
    LastName: {
      type: DataTypes.STRING(100),
      allowNull: false
    },
    Phone: {
      type: DataTypes.STRING(15)
    },
    Email: {
      type: DataTypes.STRING(200),
      allowNull: false,
      unique: 'Admin_Email_unique',
      validate: {
        isEmail: true
      }
    },
    Password: {
      type: DataTypes.TEXT,
      allowNull: false
    },
    Condition: {
      type: DataTypes.TEXT
    },
    ConditionMin: {
      type: DataTypes.TEXT
    },
    Photo: {
      type: DataTypes.TEXT
    },
    Code: {
      type: DataTypes.TEXT
    }
  });

  Admin.prototype.comparePassword = async function(password) {
    return await bcrypt.compare(password, this.Password);
  };
  
  return Admin;
};