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

workDate: {
        type: DataTypes.DATE,
      
      

      },

scheduledTimeIn: {
        type: DataTypes.TEXT,
      
      

      },

scheduledTimeOut: {
        type: DataTypes.TEXT,
      
      

      },

actualTimeIn: {
        type: DataTypes.DATE,
      
      

      },

actualTimeOut: {
        type: DataTypes.DATE,
      
      

      },

tardinessMinutes: {
        type: DataTypes.INTEGER,
      
      

      },

undertimeMinutes: {
        type: DataTypes.INTEGER,
      
      

      },

overtimeMinutes: {
        type: DataTypes.INTEGER,
      
      

      },

nightDiffHours: {
        type: DataTypes.DECIMAL,
      
      

      },

workType: {
        type: DataTypes.ENUM,
      
      

        values: [

"REGULAR",


"REST_DAY",


"REGULAR_HOLIDAY",


"SPECIAL_HOLIDAY"

        ],

      },

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

      },

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

      },

halfDayType: {
        type: DataTypes.ENUM,
      
      

        values: [

"AM",


"PM"

        ],

      },

source: {
        type: DataTypes.ENUM,
      
      

        values: [

"BIOMETRIC",


"MANUAL",


"SYSTEM"

        ],

      },

modificationReason: {
        type: DataTypes.TEXT,
      
      

      },

approvedAt: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.time_records.belongsTo(db.shifts, {
      as: 'shift',
      foreignKey: {
        name: 'shiftId',
      },
      constraints: false,
    });

    db.time_records.belongsTo(db.users, {
      as: 'modifiedByUser',
      foreignKey: {
        name: 'modifiedByUserId',
      },
      constraints: false,
    });

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

    db.time_records.belongsTo(db.payroll_runs, {
      as: 'payrollRun',
      foreignKey: {
        name: 'payrollRunId',
      },
      constraints: false,
    });




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

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



  return time_records;
};


