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

dateFrom: {
        type: DataTypes.DATE,
      
      

      },

dateTo: {
        type: DataTypes.DATE,
      
      

      },

totalDays: {
        type: DataTypes.DECIMAL,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"APPLIED",


"PENDING_MANAGER",


"PENDING_HR",


"APPROVED",


"REJECTED",


"CANCELLED"

        ],

      },

managerNote: {
        type: DataTypes.TEXT,
      
      

      },

hrNote: {
        type: DataTypes.TEXT,
      
      

      },

approvedAt: {
        type: DataTypes.DATE,
      
      

      },

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

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

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

    db.leave_applications.belongsTo(db.users, {
      as: 'approvedByUser',
      foreignKey: {
        name: 'approvedByUserId',
      },
      constraints: false,
    });




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

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



  return leave_applications;
};


