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

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

      },

points_awarded: {
        type: DataTypes.INTEGER,
      
      

      },

answer_time_ms: {
        type: DataTypes.INTEGER,
      
      

      },

answered_at: {
        type: DataTypes.DATE,
      
      

      },

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

  player_answers.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.player_answers.belongsTo(db.match_players, {
      as: 'match_player',
      foreignKey: {
        name: 'match_playerId',
      },
      constraints: false,
    });

    db.player_answers.belongsTo(db.match_questions, {
      as: 'match_question',
      foreignKey: {
        name: 'match_questionId',
      },
      constraints: false,
    });

    db.player_answers.belongsTo(db.question_answers, {
      as: 'selected_answer',
      foreignKey: {
        name: 'selected_answerId',
      },
      constraints: false,
    });




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

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



  return player_answers;
};


