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

step_no: {
        type: DataTypes.INTEGER,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

decision_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"approve",


"review",


"post"

        ],

      },

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

      },

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

  workflow_steps.associate = (db) => {


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







































    db.workflow_steps.hasMany(db.voucher_approvals, {
      as: 'voucher_approvals_workflow_step',
      foreignKey: {
          name: 'workflow_stepId',
      },
      constraints: false,
    });











//end loop



    db.workflow_steps.belongsTo(db.approval_workflows, {
      as: 'workflow',
      foreignKey: {
        name: 'workflowId',
      },
      constraints: false,
    });

    db.workflow_steps.belongsTo(db.roles, {
      as: 'approver_role',
      foreignKey: {
        name: 'approver_roleId',
      },
      constraints: false,
    });




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

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



  return workflow_steps;
};


