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

question_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"multiple_choice",


"true_false",


"short_answer",


"open_ended",


"fill_blank"

        ],

      },

prompt: {
        type: DataTypes.TEXT,
      
      

      },

choices_json: {
        type: DataTypes.TEXT,
      
      

      },

correct_answer: {
        type: DataTypes.TEXT,
      
      

      },

explanation: {
        type: DataTypes.TEXT,
      
      

      },

points: {
        type: DataTypes.INTEGER,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  quiz_questions.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.quiz_questions.belongsTo(db.quizzes, {
      as: 'quiz',
      foreignKey: {
        name: 'quizId',
      },
      constraints: false,
    });

    db.quiz_questions.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return quiz_questions;
};


