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

result_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"started",


"submitted",


"graded",


"invalidated"

        ],

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

answers_payload: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.quiz_results.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return quiz_results;
};


