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

full_name: {
        type: DataTypes.TEXT,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

bio: {
        type: DataTypes.TEXT,
      
      

      },

display_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  ir_management_members.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.ir_management_members.belongsTo(db.ir_companies, {
      as: 'ir_company',
      foreignKey: {
        name: 'ir_companyId',
      },
      constraints: false,
    });



    db.ir_management_members.hasMany(db.file, {
      as: 'profile_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.ir_management_members.getTableName(),
        belongsToColumn: 'profile_images',
      },
    });


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

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



  return ir_management_members;
};


