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

name: {
        type: DataTypes.TEXT,
      
      

      },

min_points: {
        type: DataTypes.INTEGER,
      
      

      },

max_points: {
        type: DataTypes.INTEGER,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  rank_tiers.associate = (db) => {


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





















    db.rank_tiers.hasMany(db.user_ranks, {
      as: 'user_ranks_rank_tier',
      foreignKey: {
          name: 'rank_tierId',
      },
      constraints: false,
    });



















//end loop





    db.rank_tiers.hasMany(db.file, {
      as: 'icon_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.rank_tiers.getTableName(),
        belongsToColumn: 'icon_images',
      },
    });


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

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



  return rank_tiers;
};


