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

answer_text: {
        type: DataTypes.TEXT,
      
      

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

graded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  exam_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.exam_answers.belongsTo(db.exam_attempts, {
      as: 'exam_attempt',
      foreignKey: {
        name: 'exam_attemptId',
      },
      constraints: false,
    });

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

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

    db.exam_answers.belongsTo(db.users, {
      as: 'graded_by',
      foreignKey: {
        name: 'graded_byId',
      },
      constraints: false,
    });

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




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

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



  return exam_answers;
};


