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

l1_threshold_usd: {
        type: DataTypes.DECIMAL,
      
      

      },

l2_threshold_usd: {
        type: DataTypes.DECIMAL,
      
      

      },

l3_threshold_usd: {
        type: DataTypes.DECIMAL,
      
      

      },

l4_threshold_usd: {
        type: DataTypes.DECIMAL,
      
      

      },

sla_approval_hours: {
        type: DataTypes.INTEGER,
      
      

      },

sla_procurement_hours: {
        type: DataTypes.INTEGER,
      
      

      },

sla_reception_hours: {
        type: DataTypes.INTEGER,
      
      

      },

rate_limit_profile: {
        type: DataTypes.ENUM,
      
      

        values: [

"standard",


"strict",


"custom"

        ],

      },

require_reject_reason: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

require_return_comment: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  workflow_rules.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.workflow_rules.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

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




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

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



  return workflow_rules;
};


