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

override_title: {
        type: DataTypes.TEXT,
      
      

      },

frequency: {
        type: DataTypes.ENUM,
      
      

        values: [

"inherit",


"one_time",


"monthly",


"quarterly",


"half_yearly",


"yearly",


"event_based"

        ],

      },

due_day_of_month: {
        type: DataTypes.INTEGER,
      
      

      },

due_month_of_year: {
        type: DataTypes.INTEGER,
      
      

      },

grace_days: {
        type: DataTypes.INTEGER,
      
      

      },

risk_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"inherit",


"low",


"medium",


"high",


"critical"

        ],

      },

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

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

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

  compliance_rule_overrides.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_rule_overrides.belongsTo(db.companies, {
      as: 'company',
      foreignKey: {
        name: 'companyId',
      },
      constraints: false,
    });

    db.compliance_rule_overrides.belongsTo(db.compliance_templates, {
      as: 'template',
      foreignKey: {
        name: 'templateId',
      },
      constraints: false,
    });

    db.compliance_rule_overrides.belongsTo(db.branches, {
      as: 'branch',
      foreignKey: {
        name: 'branchId',
      },
      constraints: false,
    });

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




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

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



  return compliance_rule_overrides;
};


