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

request_id: {
        type: DataTypes.TEXT,
      
      

      },

payload: {
        type: DataTypes.TEXT,
      
      

      },

priority: {
        type: DataTypes.INTEGER,
      
      

      },

attempts: {
        type: DataTypes.INTEGER,
      
      

      },

next_retry: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"processing",


"failed",


"completed"

        ],

      },

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

  request_queue.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.request_queue.belongsTo(db.fill_sessions, {
      as: 'session',
      foreignKey: {
        name: 'sessionId',
      },
      constraints: false,
    });




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

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



  return request_queue;
};


