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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"en_attente",


"approuve",


"rejete"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

reviewed_at: {
        type: DataTypes.DATE,
      
      

      },

review_comment: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.account_approvals.belongsTo(db.users, {
      as: 'requested_by_user',
      foreignKey: {
        name: 'requested_by_userId',
      },
      constraints: false,
    });

    db.account_approvals.belongsTo(db.users, {
      as: 'reviewed_by_user',
      foreignKey: {
        name: 'reviewed_by_userId',
      },
      constraints: false,
    });




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

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



  return account_approvals;
};


