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

choice_label: {
        type: DataTypes.TEXT,
      
      

      },

choice_text: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

order_number: {
        type: DataTypes.INTEGER,
      
      

      },

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

  exam_question_choices.associate = (db) => {


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
























    db.exam_question_choices.hasMany(db.exam_answers, {
      as: 'exam_answers_selected_choice',
      foreignKey: {
          name: 'selected_choiceId',
      },
      constraints: false,
    });







//end loop



    db.exam_question_choices.belongsTo(db.exam_questions, {
      as: 'exam_question',
      foreignKey: {
        name: 'exam_questionId',
      },
      constraints: false,
    });

    db.exam_question_choices.belongsTo(db.schools, {
      as: 'schools',
      foreignKey: {
        name: 'schoolsId',
      },
      constraints: false,
    });




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

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



  return exam_question_choices;
};


