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

amountDeducted: {
        type: DataTypes.DECIMAL,
      
      

      },

deductionDate: {
        type: DataTypes.DATE,
      
      

      },

balanceBefore: {
        type: DataTypes.DECIMAL,
      
      

      },

balanceAfter: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

deferredReason: {
        type: DataTypes.TEXT,
      
      

      },

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

  loan_deductions.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.loan_deductions.belongsTo(db.employee_loans, {
      as: 'loan',
      foreignKey: {
        name: 'loanId',
      },
      constraints: false,
    });

    db.loan_deductions.belongsTo(db.payroll_items, {
      as: 'payrollItem',
      foreignKey: {
        name: 'payrollItemId',
      },
      constraints: false,
    });




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

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



  return loan_deductions;
};


