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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"started",


"submitted",


"passed",


"failed",


"abandoned"

        ],

      },

score_percent: {
        type: DataTypes.INTEGER,
      
      

      },

correct_count: {
        type: DataTypes.INTEGER,
      
      

      },

total_count: {
        type: DataTypes.INTEGER,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

coins_awarded: {
        type: DataTypes.INTEGER,
      
      

      },

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

  quiz_attempts.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_attempts.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.quiz_attempts.belongsTo(db.quiz_definitions, {
      as: 'quiz_definition',
      foreignKey: {
        name: 'quiz_definitionId',
      },
      constraints: false,
    });




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

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



  return quiz_attempts;
};


