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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_started",


"in_progress",


"completed"

        ],

      },

progress_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

last_checkpoint: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.lesson_progress.belongsTo(db.lessons, {
      as: 'lesson',
      foreignKey: {
        name: 'lessonId',
      },
      constraints: false,
    });




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

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



  return lesson_progress;
};


