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

level: {
        type: DataTypes.ENUM,
      
      

        values: [

"L1",


"L2",


"L3",


"L4"

        ],

      },

decision: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"approved",


"rejected",


"returned"

        ],

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

assigned_at: {
        type: DataTypes.DATE,
      
      

      },

decided_at: {
        type: DataTypes.DATE,
      
      

      },

sla_due_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  approval_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.approval_steps.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.approval_steps.belongsTo(db.requisitions, {
      as: 'requisition',
      foreignKey: {
        name: 'requisitionId',
      },
      constraints: false,
    });

    db.approval_steps.belongsTo(db.users, {
      as: 'assigned_approver',
      foreignKey: {
        name: 'assigned_approverId',
      },
      constraints: false,
    });

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




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

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



  return approval_steps;
};


