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

action_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"approved",


"rejected",


"corrected",


"needs_more_info"

        ],

      },

correction_json: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

action_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.review_actions.belongsTo(db.authorization_cases, {
      as: 'authorization_case',
      foreignKey: {
        name: 'authorization_caseId',
      },
      constraints: false,
    });

    db.review_actions.belongsTo(db.ai_outputs, {
      as: 'ai_output',
      foreignKey: {
        name: 'ai_outputId',
      },
      constraints: false,
    });

    db.review_actions.belongsTo(db.users, {
      as: 'reviewer_user',
      foreignKey: {
        name: 'reviewer_userId',
      },
      constraints: false,
    });




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

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



  return review_actions;
};


