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

template_name: {
        type: DataTypes.TEXT,
      
      

      },

workflow_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"joiner",


"mover",


"leaver",


"privileged_access_assignment",


"privileged_access_removal",


"mfa_enforcement",


"quarterly_access_review",


"service_account_review",


"break_glass_exception",


"emergency_access_use"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

risk_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

owner_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"org_admin",


"compliance_manager",


"security_manager",


"iam_operator",


"auditor",


"read_only_client"

        ],

      },

source_trigger_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"HR",


"Ticket",


"Manual",


"Automated",


"Scheduled"

        ],

      },

recurrence_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"none",


"weekly",


"monthly",


"quarterly",


"semi_annual",


"annual"

        ],

      },

default_required_fields: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return workflow_templates;
};


