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

action: {
        type: DataTypes.ENUM,
      
      

        values: [

"USER_UPDATE",


"USER_DELETE",


"COIN_ADJUST",


"PRODUCT_CREATE",


"PRODUCT_UPDATE",


"PRODUCT_DELETE",


"CODE_CREATE",


"CODE_UPDATE",


"CODE_DELETE",


"ITEM_CREATE",


"ITEM_UPDATE",


"ITEM_DELETE",


"MEMBERSHIP_PLAN_UPDATE",


"OTHER"

        ],

      },

entity_name: {
        type: DataTypes.TEXT,
      
      

      },

entity_reference: {
        type: DataTypes.TEXT,
      
      

      },

occurred_at: {
        type: DataTypes.DATE,
      
      

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

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

  admin_audit_logs.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.admin_audit_logs.belongsTo(db.users, {
      as: 'admin_user',
      foreignKey: {
        name: 'admin_userId',
      },
      constraints: false,
    });




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

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



  return admin_audit_logs;
};


