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

trophy_name: {
        type: DataTypes.TEXT,
      
      

      },

trophy_description: {
        type: DataTypes.TEXT,
      
      

      },

trophy_tier: {
        type: DataTypes.ENUM,
      
      

        values: [

"star_1",


"star_2",


"star_3",


"milestone",


"special"

        ],

      },

icon_key: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  trophies.associate = (db) => {


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
















    db.trophies.hasMany(db.user_trophies, {
      as: 'user_trophies_trophy',
      foreignKey: {
          name: 'trophyId',
      },
      constraints: false,
    });













//end loop






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

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



  return trophies;
};


