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

answer_text: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

points_earned: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  quiz_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.quiz_answers.belongsTo(db.quiz_submissions, {
      as: 'quiz_submission',
      foreignKey: {
        name: 'quiz_submissionId',
      },
      constraints: false,
    });

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

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




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

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



  return quiz_answers;
};


