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

title: {
        type: DataTypes.TEXT,
      
      

      },

jobLevel: {
        type: DataTypes.ENUM,
      
      

        values: [

"RANK_AND_FILE",


"SUPERVISOR",


"MANAGER",


"OFFICER"

        ],

      },

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

      },

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

  positions.associate = (db) => {


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














    db.positions.hasMany(db.employees, {
      as: 'employees_position',
      foreignKey: {
          name: 'positionId',
      },
      constraints: false,
    });
































//end loop






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

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



  return positions;
};


