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

email: {
        type: DataTypes.TEXT,
      
      

      },

display_name: {
        type: DataTypes.TEXT,
      
      

      },

role: {
        type: DataTypes.ENUM,
      
      

        values: [

"super_admin",


"moderator",


"support",


"analyst"

        ],

      },

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

      },

last_login_at: {
        type: DataTypes.DATE,
      
      

      },

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

  admin_users.associate = (db) => {


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
















    db.admin_users.hasMany(db.reports, {
      as: 'reports_assigned_moderator',
      foreignKey: {
          name: 'assigned_moderatorId',
      },
      constraints: false,
    });









    db.admin_users.hasMany(db.content_moderation_items, {
      as: 'content_moderation_items_reviewed_by',
      foreignKey: {
          name: 'reviewed_byId',
      },
      constraints: false,
    });





//end loop






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

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



  return admin_users;
};


