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

year: {
        type: DataTypes.INTEGER,
      
      

      },

openingBalance: {
        type: DataTypes.DECIMAL,
      
      

      },

earnedThisYear: {
        type: DataTypes.DECIMAL,
      
      

      },

usedYtd: {
        type: DataTypes.DECIMAL,
      
      

      },

forfeited: {
        type: DataTypes.DECIMAL,
      
      

      },

convertedToCash: {
        type: DataTypes.DECIMAL,
      
      

      },

currentBalance: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  leave_balances.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.leave_balances.belongsTo(db.employees, {
      as: 'employee',
      foreignKey: {
        name: 'employeeId',
      },
      constraints: false,
    });

    db.leave_balances.belongsTo(db.leave_types, {
      as: 'leaveType',
      foreignKey: {
        name: 'leaveTypeId',
      },
      constraints: false,
    });




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

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



  return leave_balances;
};


