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

risk_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"excessive_discounts",


"refund_abuse",


"cash_discrepancy",


"inventory_shrinkage",


"supplier_overpricing",


"void_rate",


"other"

        ],

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"investigating",


"resolved",


"dismissed"

        ],

      },

detected_at: {
        type: DataTypes.DATE,
      
      

      },

title_text: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

source_reference: {
        type: DataTypes.TEXT,
      
      

      },

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

  risk_alerts.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_alerts.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

    db.risk_alerts.belongsTo(db.users, {
      as: 'assigned_to',
      foreignKey: {
        name: 'assigned_toId',
      },
      constraints: false,
    });

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




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

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



  return risk_alerts;
};


