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

name: {
        type: DataTypes.TEXT,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

step_order: {
        type: DataTypes.INTEGER,
      
      

      },

step_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"prepare",


"payment",


"participant_precheck",


"participant_auth",


"review",


"sign",


"finalize",


"release"

        ],

      },

is_blocking: {
        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












































//end loop



    db.workflow_steps.belongsTo(db.workflow_definitions, {
      as: 'workflow_definition',
      foreignKey: {
        name: 'workflow_definitionId',
      },
      constraints: false,
    });

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




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

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



  return workflow_steps;
};


