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

template_name: {
        type: DataTypes.TEXT,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

frequency: {
        type: DataTypes.ENUM,
      
      

        values: [

"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,
      
      

      },

applies_to_business_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"any",


"proprietorship",


"partnership",


"llp",


"private_limited",


"public_limited",


"opc",


"huf",


"trust",


"society",


"ngo",


"other"

        ],

      },

applies_to_industry: {
        type: DataTypes.TEXT,
      
      

      },

applies_to_state: {
        type: DataTypes.ENUM,
      
      

        values: [

"any",


"andaman_and_nicobar_islands",


"andhra_pradesh",


"arunachal_pradesh",


"assam",


"bihar",


"chandigarh",


"chhattisgarh",


"dadra_and_nagar_haveli_and_daman_and_diu",


"delhi",


"goa",


"gujarat",


"haryana",


"himachal_pradesh",


"jammu_and_kashmir",


"jharkhand",


"karnataka",


"kerala",


"ladakh",


"lakshadweep",


"madhya_pradesh",


"maharashtra",


"manipur",


"meghalaya",


"mizoram",


"nagaland",


"odisha",


"puducherry",


"punjab",


"rajasthan",


"sikkim",


"tamil_nadu",


"telangana",


"tripura",


"uttar_pradesh",


"uttarakhand",


"west_bengal"

        ],

      },

min_employee_count: {
        type: DataTypes.INTEGER,
      
      

      },

max_employee_count: {
        type: DataTypes.INTEGER,
      
      

      },

risk_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

legal_reference: {
        type: DataTypes.TEXT,
      
      

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  compliance_templates.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity












    db.compliance_templates.hasMany(db.company_compliances, {
      as: 'company_compliances_template',
      foreignKey: {
          name: 'templateId',
      },
      constraints: false,
    });















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





//end loop



    db.compliance_templates.belongsTo(db.compliance_categories, {
      as: 'category',
      foreignKey: {
        name: 'categoryId',
      },
      constraints: false,
    });

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




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

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



  return compliance_templates;
};


