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

name: {
        type: DataTypes.TEXT,
      
      

      },

period_start: {
        type: DataTypes.DATE,
      
      

      },

period_end: {
        type: DataTypes.DATE,
      
      

      },

run_date: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"finalized",


"exported"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  payroll_runs.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity













    db.payroll_runs.hasMany(db.payroll_line_items, {
      as: 'payroll_line_items_payroll_run',
      foreignKey: {
          name: 'payroll_runId',
      },
      constraints: false,
    });



//end loop






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

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



  return payroll_runs;
};


