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

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"earning",


"deduction"

        ],

      },

adjustment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"telat_denda",


"tidak_hadir",


"pinjaman",


"deposit_seragam",


"refund_seragam",


"waste",


"manual_addition",


"manual_deduction",


"other"

        ],

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

effective_at: {
        type: DataTypes.DATE,
      
      

      },

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

  payroll_adjustments.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.payroll_adjustments.belongsTo(db.payroll_items, {
      as: 'payroll_item',
      foreignKey: {
        name: 'payroll_itemId',
      },
      constraints: false,
    });

    db.payroll_adjustments.belongsTo(db.users, {
      as: 'created_by_user',
      foreignKey: {
        name: 'created_by_userId',
      },
      constraints: false,
    });

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




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

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



  return payroll_adjustments;
};


