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

acted_at: {
        type: DataTypes.DATE,
      
      

      },

decision: {
        type: DataTypes.ENUM,
      
      

        values: [

"submitted",


"approved",


"rejected",


"returned"

        ],

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

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

  voucher_approvals.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.voucher_approvals.belongsTo(db.journal_vouchers, {
      as: 'voucher',
      foreignKey: {
        name: 'voucherId',
      },
      constraints: false,
    });

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

    db.voucher_approvals.belongsTo(db.users, {
      as: 'acted_by_user',
      foreignKey: {
        name: 'acted_by_userId',
      },
      constraints: false,
    });




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

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



  return voucher_approvals;
};


