module.exports = function(sequelize, DataTypes) {
  const job_positions = sequelize.define(
    'job_positions',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

code: {
        type: DataTypes.TEXT,
      
      

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

payroll_weight: {
        type: DataTypes.INTEGER,
      
      

      },

shift_schedule: {
        type: DataTypes.TEXT,
      
      

      },

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

  job_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.job_positions.hasMany(db.employees, {
      as: 'employees_job_position',
      foreignKey: {
          name: 'job_positionId',
      },
      constraints: false,
    });



















//end loop



    db.job_positions.belongsTo(db.outlets, {
      as: 'outlet',
      foreignKey: {
        name: 'outletId',
      },
      constraints: false,
    });

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




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

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



  return job_positions;
};


