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

session_token: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"finished",


"abandoned"

        ],

      },

starting_lives: {
        type: DataTypes.INTEGER,
      
      

      },

lives_remaining: {
        type: DataTypes.INTEGER,
      
      

      },

streak: {
        type: DataTypes.INTEGER,
      
      

      },

best_streak: {
        type: DataTypes.INTEGER,
      
      

      },

timer_profile: {
        type: DataTypes.ENUM,
      
      

        values: [

"normal",


"insane"

        ],

      },

mode_selection: {
        type: DataTypes.ENUM,
      
      

        values: [

"beatmap_only",


"mapper_only",


"artist_only",


"mixed"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

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

  game_sessions.associate = (db) => {


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















    db.game_sessions.hasMany(db.game_rounds, {
      as: 'game_rounds_session',
      foreignKey: {
          name: 'sessionId',
      },
      constraints: false,
    });


    db.game_sessions.hasMany(db.leaderboard_entries, {
      as: 'leaderboard_entries_session',
      foreignKey: {
          name: 'sessionId',
      },
      constraints: false,
    });





//end loop



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




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

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



  return game_sessions;
};


