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

overall_score: {
        type: DataTypes.INTEGER,
      
      

      },

factors_json: {
        type: DataTypes.TEXT,
      
      

      },

optimization_suggestions_json: {
        type: DataTypes.TEXT,
      
      

      },

analyzed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  risk_analyses.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_analyses.belongsTo(db.declarations, {
      as: 'declaration',
      foreignKey: {
        name: 'declarationId',
      },
      constraints: false,
    });

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




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

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



  return risk_analyses;
};


