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

clock_in_at: {
        type: DataTypes.DATE,
      
      

      },

clock_out_at: {
        type: DataTypes.DATE,
      
      

      },

clock_in_source: {
        type: DataTypes.TEXT,
      
      

      },

clock_out_source: {
        type: DataTypes.TEXT,
      
      

      },

worked_hours: {
        type: DataTypes.DECIMAL,
      
      

      },

break_hours: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"closed",


"corrected"

        ],

      },

note: {
        type: DataTypes.TEXT,
      
      

      },

approved_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.time_entries.belongsTo(db.employees, {
      as: 'approved_by',
      foreignKey: {
        name: 'approved_byId',
      },
      constraints: false,
    });

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




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

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



  return time_entries;
};


