const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const authentication_methods = sequelize.define(
    'authentication_methods',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

method_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"email_otp",


"sms_otp",


"bank_amount_verification",


"id_document_capture",


"face_capture",


"fingerprint",


"clave_unica"

        ],

      },

requires_hardware: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

is_active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  authentication_methods.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity




























    db.authentication_methods.hasMany(db.authentication_attempts, {
      as: 'authentication_attempts_authentication_method',
      foreignKey: {
          name: 'authentication_methodId',
      },
      constraints: false,
    });





    db.authentication_methods.hasMany(db.notification_record_items, {
      as: 'notification_record_items_authentication_method',
      foreignKey: {
          name: 'authentication_methodId',
      },
      constraints: false,
    });













//end loop



    db.authentication_methods.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




    db.authentication_methods.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.authentication_methods.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return authentication_methods;
};


