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

job_title: {
        type: DataTypes.ENUM,
      
      

        values: [

"cashier",


"stocker",


"manager",


"cleaner",


"security",


"delivery_receiver"

        ],

      },

employment_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"candidate",


"hired",


"on_leave",


"terminated"

        ],

      },

daily_wage: {
        type: DataTypes.DECIMAL,
      
      

      },

hired_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  employees.associate = (db) => {


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



























    db.employees.hasMany(db.deliveries, {
      as: 'deliveries_received_by_employee',
      foreignKey: {
          name: 'received_by_employeeId',
      },
      constraints: false,
    });





    db.employees.hasMany(db.sales_transactions, {
      as: 'sales_transactions_cashier_employee',
      foreignKey: {
          name: 'cashier_employeeId',
      },
      constraints: false,
    });





















//end loop



    db.employees.belongsTo(db.market_stores, {
      as: 'store',
      foreignKey: {
        name: 'storeId',
      },
      constraints: false,
    });

    db.employees.belongsTo(db.npcs, {
      as: 'npc',
      foreignKey: {
        name: 'npcId',
      },
      constraints: false,
    });




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

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



  return employees;
};


