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

target_kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"lesson",


"exercise",


"game",


"activity",


"course",


"path"

        ],

      },

state: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_started",


"in_progress",


"mastered",


"completed"

        ],

      },

progress_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

attempts: {
        type: DataTypes.INTEGER,
      
      

      },

last_activity_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.progress_records.belongsTo(db.content_items, {
      as: 'content_item',
      foreignKey: {
        name: 'content_itemId',
      },
      constraints: false,
    });

    db.progress_records.belongsTo(db.courses, {
      as: 'course',
      foreignKey: {
        name: 'courseId',
      },
      constraints: false,
    });

    db.progress_records.belongsTo(db.learning_paths, {
      as: 'path',
      foreignKey: {
        name: 'pathId',
      },
      constraints: false,
    });

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




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

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



  return progress_records;
};


