const bcrypt = require('bcrypt');

module.exports = (sequelize, DataTypes) => {
  const Cliente = sequelize.define('Cliente', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    Name: {
      type: DataTypes.STRING(100),
      allowNull: false
    },
    LastName: {
      type: DataTypes.STRING(100),
      allowNull: false
    },
    BirthDate: {
      type: DataTypes.DATE
    },
    Job: {
      type: DataTypes.STRING(100)
    },
    Direction: {
      type: DataTypes.STRING(100)
    },
    Phone: {
      type: DataTypes.STRING(15)
    },
    Gender: {
      type: DataTypes.STRING(10)
    },
    CivilStatus: {
      type: DataTypes.STRING(25)
    },
    DocumentNumber: {
      type: DataTypes.STRING(15),
      unique: 'Cliente_DocumentNumber_unique',
      allowNull: false
    },
    Email: {
      type: DataTypes.STRING(200),
      validate: {
        isEmail: true
      }
    },
    Password: {
      type: DataTypes.TEXT
    },
    Photo: {
      type: DataTypes.TEXT
    },
    Code: {
      type: DataTypes.TEXT
    },
    Condition: {
      type: DataTypes.TEXT
    },
    G: {
      type: DataTypes.TEXT
    },
    P: {
      type: DataTypes.TEXT
    },
    A: {
      type: DataTypes.TEXT
    },
    C: {
      type: DataTypes.TEXT
    },
    Fum: {
      type: DataTypes.DATE
    },
    Papsmear: {
      type: DataTypes.TEXT
    },
    Bloodtype: {
      type: DataTypes.TEXT
    },
    Others: {
      type: DataTypes.TEXT
    },
    Othershereditary: {
      type: DataTypes.TEXT
    },
    Otherspathological: {
      type: DataTypes.TEXT
    },
    Medicine: {
      type: DataTypes.TEXT
    },
    PreviousSurgeries: {
      type: DataTypes.TEXT,
      defaultValue: 'Ninguna'
    }
  });

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