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

review_target: {
        type: DataTypes.ENUM,
      
      

        values: [

"refresh_job",


"knowledge_document",


"knowledge_chunk",


"safety_policy",


"brain_profile",


"skill_module"

        ],

      },

reviewed_at: {
        type: DataTypes.DATE,
      
      

      },

decision: {
        type: DataTypes.ENUM,
      
      

        values: [

"approved",


"approved_with_changes",


"rejected"

        ],

      },

alignment_score: {
        type: DataTypes.DECIMAL,
      
      

      },

review_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return approval_reviews;
};


