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

title: {
        type: DataTypes.TEXT,
      
      

      },

activity_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"simulation",


"flashcards",


"drag_drop",


"coding",


"lab",


"discussion"

        ],

      },

difficulty: {
        type: DataTypes.ENUM,
      
      

        values: [

"easy",


"medium",


"hard",


"expert"

        ],

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

activity_url: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

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

  interactive_activities.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity











    db.interactive_activities.hasMany(db.content_items, {
      as: 'content_items_activity',
      foreignKey: {
          name: 'activityId',
      },
      constraints: false,
    });





    db.interactive_activities.hasMany(db.attempts, {
      as: 'attempts_activity',
      foreignKey: {
          name: 'activityId',
      },
      constraints: false,
    });


















//end loop



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



    db.interactive_activities.hasMany(db.file, {
      as: 'resources',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.interactive_activities.getTableName(),
        belongsToColumn: 'resources',
      },
    });


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

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



  return interactive_activities;
};


