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

name: {
        type: DataTypes.TEXT,
      
      

      },

pay_method: {
        type: DataTypes.ENUM,
      
      

        values: [

"hourly",


"commission"

        ],

      },

hourly_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

commission_rate: {
        type: DataTypes.DECIMAL,
      
      

      },

workers_comp_percentage: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  pay_types.associate = (db) => {


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








    db.pay_types.hasMany(db.employee_pay_types, {
      as: 'employee_pay_types_pay_type',
      foreignKey: {
          name: 'pay_typeId',
      },
      constraints: false,
    });



    db.pay_types.hasMany(db.job_logs, {
      as: 'job_logs_pay_type',
      foreignKey: {
          name: 'pay_typeId',
      },
      constraints: false,
    });






//end loop






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

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



  return pay_types;
};