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

subject_display_name: {
        type: DataTypes.TEXT,
      
      

      },

subject_identifier: {
        type: DataTypes.TEXT,
      
      

      },

system_name: {
        type: DataTypes.TEXT,
      
      

      },

entitlements_reviewed: {
        type: DataTypes.TEXT,
      
      

      },

reviewer_decision: {
        type: DataTypes.ENUM,
      
      

        values: [

"approve",


"revoke",


"needs_investigation",


"no_change"

        ],

      },

justification: {
        type: DataTypes.TEXT,
      
      

      },

action_required: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"completed",


"escalated"

        ],

      },

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

  access_review_items.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.access_review_items.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.access_review_items.belongsTo(db.access_reviews, {
      as: 'access_review',
      foreignKey: {
        name: 'access_reviewId',
      },
      constraints: false,
    });




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

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



  return access_review_items;
};


