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,
      },

board_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"all_time",


"daily_seed"

        ],

      },

seed_key: {
        type: DataTypes.TEXT,
      
      

      },

score: {
        type: DataTypes.INTEGER,
      
      

      },

rounds_survived: {
        type: DataTypes.INTEGER,
      
      

      },

best_streak: {
        type: DataTypes.INTEGER,
      
      

      },

achieved_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.game_sessions, {
      as: 'session',
      foreignKey: {
        name: 'sessionId',
      },
      constraints: false,
    });




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

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



  return leaderboard_entries;
};


