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

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"check_in",


"check_out",


"absence",


"retard"

        ],

      },

event_time: {
        type: DataTypes.DATE,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

distance_meters: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

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

  attendance_events.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.attendance_events.belongsTo(db.restaurants, {
      as: 'restaurant',
      foreignKey: {
        name: 'restaurantId',
      },
      constraints: false,
    });

    db.attendance_events.belongsTo(db.users, {
      as: 'staff_user',
      foreignKey: {
        name: 'staff_userId',
      },
      constraints: false,
    });

    db.attendance_events.belongsTo(db.work_shifts, {
      as: 'work_shift',
      foreignKey: {
        name: 'work_shiftId',
      },
      constraints: false,
    });




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

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



  return attendance_events;
};


