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

scope: {
        type: DataTypes.ENUM,
      
      

        values: [

"global",


"class",


"event",


"mode"

        ],

      },

rank_position: {
        type: DataTypes.INTEGER,
      
      

      },

score_value: {
        type: DataTypes.INTEGER,
      
      

      },

period_start_at: {
        type: DataTypes.DATE,
      
      

      },

period_end_at: {
        type: DataTypes.DATE,
      
      

      },

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

  leaderboard_entries.associate = (db) => {


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





































//end loop



    db.leaderboard_entries.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.leaderboard_entries.belongsTo(db.events, {
      as: 'event',
      foreignKey: {
        name: 'eventId',
      },
      constraints: false,
    });

    db.leaderboard_entries.belongsTo(db.game_modes, {
      as: 'mode',
      foreignKey: {
        name: 'modeId',
      },
      constraints: false,
    });




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

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



  return leaderboard_entries;
};


