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

alert_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"missing_document",


"budget_overrun",


"segregation_of_duties",


"vendor_document_expiry",


"contract_expiry",


"payment_overdue",


"other"

        ],

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"info",


"warning",


"high",


"critical"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

record_type: {
        type: DataTypes.TEXT,
      
      

      },

record_key: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"acknowledged",


"resolved",


"dismissed"

        ],

      },

detected_at: {
        type: DataTypes.DATE,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.compliance_alerts.belongsTo(db.users, {
      as: 'assigned_to_user',
      foreignKey: {
        name: 'assigned_to_userId',
      },
      constraints: false,
    });




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

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



  return compliance_alerts;
};


