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

full_name: {
        type: DataTypes.TEXT,
      
      

      },

gmail_address: {
        type: DataTypes.TEXT,
      
      

      },

access_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"super_admin",


"admin",


"viewer"

        ],

      },

department: {
        type: DataTypes.TEXT,
      
      

      },

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

  admins.associate = (db) => {


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












    db.admins.hasMany(db.medicine_dispatches, {
      as: 'medicine_dispatches_approved_by_admin',
      foreignKey: {
          name: 'approved_by_adminId',
      },
      constraints: false,
    });



    db.admins.hasMany(db.medical_camps, {
      as: 'medical_camps_created_by_admin',
      foreignKey: {
          name: 'created_by_adminId',
      },
      constraints: false,
    });














//end loop



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




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

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



  return admins;
};


