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

badge_key: {
        type: DataTypes.TEXT,
      
      

      },

name_bn: {
        type: DataTypes.TEXT,
      
      

      },

name_en: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  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.badges.hasMany(db.user_badges, {
      as: 'user_badges_badge',
      foreignKey: {
          name: 'badgeId',
      },
      constraints: false,
    });











//end loop






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

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



  return badges;
};


