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

rating: {
        type: DataTypes.ENUM,
      
      

        values: [

"again",


"hard",


"good",


"easy"

        ],

      },

response_time_ms: {
        type: DataTypes.INTEGER,
      
      

      },

is_correct: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

reviewed_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.review_events.belongsTo(db.flashcards, {
      as: 'flashcard',
      foreignKey: {
        name: 'flashcardId',
      },
      constraints: false,
    });

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




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

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



  return review_events;
};


