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

attempted_at: {
        type: DataTypes.DATE,
      
      

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

accuracy: {
        type: DataTypes.DECIMAL,
      
      

      },

duration_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

result: {
        type: DataTypes.ENUM,
      
      

        values: [

"success",


"partial",


"failed"

        ],

      },

raw_response: {
        type: DataTypes.TEXT,
      
      

      },

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

  cognitive_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.cognitive_attempts.belongsTo(db.cognitive_sessions, {
      as: 'session',
      foreignKey: {
        name: 'sessionId',
      },
      constraints: false,
    });

    db.cognitive_attempts.belongsTo(db.cognitive_exercises, {
      as: 'exercise',
      foreignKey: {
        name: 'exerciseId',
      },
      constraints: false,
    });

    db.cognitive_attempts.belongsTo(db.accounts, {
      as: 'accounts',
      foreignKey: {
        name: 'accountsId',
      },
      constraints: false,
    });




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

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



  return cognitive_attempts;
};


