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

test_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"stroop",


"trail_making",


"n_back",


"digit_span",


"reaction_time"

        ],

      },

taken_at: {
        type: DataTypes.DATE,
      
      

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

duration_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

details_json: {
        type: DataTypes.TEXT,
      
      

      },

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

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




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

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



  return cognitive_tests;
};


