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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"accepted",


"rejected",


"expired",


"processed"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

processed_at: {
        type: DataTypes.DATE,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

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

  revocation_requests.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.revocation_requests.belongsTo(db.signing_actions, {
      as: 'signing_action',
      foreignKey: {
        name: 'signing_actionId',
      },
      constraints: false,
    });

    db.revocation_requests.belongsTo(db.contract_participants, {
      as: 'requested_by_participant',
      foreignKey: {
        name: 'requested_by_participantId',
      },
      constraints: false,
    });

    db.revocation_requests.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return revocation_requests;
};


