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

name: {
        type: DataTypes.TEXT,
      
      

      },

applies_to: {
        type: DataTypes.ENUM,
      
      

        values: [

"journal_voucher"

        ],

      },

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

      },

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

  approval_workflows.associate = (db) => {


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






































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












//end loop



    db.approval_workflows.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });




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

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



  return approval_workflows;
};


