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

round_number: {
        type: DataTypes.INTEGER,
      
      

      },

round_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"beatmap",


"mapper",


"artist"

        ],

      },

state: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"answered",


"timed_out",


"resolved"

        ],

      },

time_limit_ms: {
        type: DataTypes.INTEGER,
      
      

      },

presented_at: {
        type: DataTypes.DATE,
      
      

      },

answered_at: {
        type: DataTypes.DATE,
      
      

      },

player_choice: {
        type: DataTypes.ENUM,
      
      

        values: [

"a",


"b",


"none"

        ],

      },

correct_choice: {
        type: DataTypes.ENUM,
      
      

        values: [

"a",


"b"

        ],

      },

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

      },

lose_reason: {
        type: DataTypes.ENUM,
      
      

        values: [

"wrong",


"timeout",


"none"

        ],

      },

value_a: {
        type: DataTypes.INTEGER,
      
      

      },

value_b: {
        type: DataTypes.INTEGER,
      
      

      },

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

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

    db.game_rounds.belongsTo(db.beatmaps, {
      as: 'option_a_beatmap',
      foreignKey: {
        name: 'option_a_beatmapId',
      },
      constraints: false,
    });

    db.game_rounds.belongsTo(db.beatmaps, {
      as: 'option_b_beatmap',
      foreignKey: {
        name: 'option_b_beatmapId',
      },
      constraints: false,
    });




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

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



  return game_rounds;
};


