const bcrypt = require('bcrypt');

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

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