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 security_events = sequelize.define(
    'security_events',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"login_success",


"login_failed",


"two_factor_challenge",


"face_verification_pass",


"face_verification_fail",


"permission_denied",


"suspicious_activity",


"data_export"

        ],

      },

event_at: {
        type: DataTypes.DATE,
      
      

      },

ip_address: {
        type: DataTypes.TEXT,
      
      

      },

user_agent: {
        type: DataTypes.TEXT,
      
      

      },

risk_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

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

  security_events.associate = (db) => {


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































//end loop



    db.security_events.belongsTo(db.schools, {
      as: 'school',
      foreignKey: {
        name: 'schoolId',
      },
      constraints: false,
    });

    db.security_events.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });




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

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



  return security_events;
};


