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

name_text: {
        type: DataTypes.TEXT,
      
      

      },

description_text: {
        type: DataTypes.TEXT,
      
      

      },

rarity: {
        type: DataTypes.ENUM,
      
      

        values: [

"common",


"rare",


"epic",


"legendary"

        ],

      },

points_value: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  gamification_badges.associate = (db) => {


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

























    db.gamification_badges.hasMany(db.user_badges, {
      as: 'user_badges_badge',
      foreignKey: {
          name: 'badgeId',
      },
      constraints: false,
    });



//end loop





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


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

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



  return gamification_badges;
};


