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

question_index: {
        type: DataTypes.INTEGER,
      
      

      },

revealed_at: {
        type: DataTypes.DATE,
      
      

      },

closed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  match_questions.associate = (db) => {


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


























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












//end loop



    db.match_questions.belongsTo(db.matches, {
      as: 'match',
      foreignKey: {
        name: 'matchId',
      },
      constraints: false,
    });

    db.match_questions.belongsTo(db.quiz_questions, {
      as: 'quiz_question',
      foreignKey: {
        name: 'quiz_questionId',
      },
      constraints: false,
    });




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

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



  return match_questions;
};


