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

algorithm: {
        type: DataTypes.ENUM,
      
      

        values: [

"sm2",


"fsrs_v4",


"leitner"

        ],

      },

repetitions: {
        type: DataTypes.INTEGER,
      
      

      },

lapses: {
        type: DataTypes.INTEGER,
      
      

      },

ease_factor: {
        type: DataTypes.DECIMAL,
      
      

      },

interval_days: {
        type: DataTypes.INTEGER,
      
      

      },

stability: {
        type: DataTypes.DECIMAL,
      
      

      },

difficulty: {
        type: DataTypes.DECIMAL,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

last_reviewed_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

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

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




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

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



  return spaced_repetition_states;
};


