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

work_date: {
        type: DataTypes.DATE,
      
      

      },

hours: {
        type: DataTypes.DECIMAL,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

approval_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"rejected"

        ],

      },

approved_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.overtime_logs.belongsTo(db.outlets, {
      as: 'outlet',
      foreignKey: {
        name: 'outletId',
      },
      constraints: false,
    });

    db.overtime_logs.belongsTo(db.users, {
      as: 'approved_by_user',
      foreignKey: {
        name: 'approved_by_userId',
      },
      constraints: false,
    });

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




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

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



  return overtime_logs;
};


