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

assessed_at: {
        type: DataTypes.DATE,
      
      

      },

scope: {
        type: DataTypes.ENUM,
      
      

        values: [

"organization",


"business_unit",


"asset",


"application",


"cloud_account"

        ],

      },

overall_risk_score: {
        type: DataTypes.DECIMAL,
      
      

      },

risk_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

top_risks: {
        type: DataTypes.TEXT,
      
      

      },

recommendations: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.risk_assessments.belongsTo(db.assets, {
      as: 'asset',
      foreignKey: {
        name: 'assetId',
      },
      constraints: false,
    });




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

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



  return risk_assessments;
};


