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

title: {
        type: DataTypes.TEXT,
      
      

      },

content_kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"lesson",


"exercise",


"game",


"activity"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

recommended_minutes: {
        type: DataTypes.INTEGER,
      
      

      },

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

  content_items.associate = (db) => {


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














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



















//end loop



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

    db.content_items.belongsTo(db.exercises, {
      as: 'exercise',
      foreignKey: {
        name: 'exerciseId',
      },
      constraints: false,
    });

    db.content_items.belongsTo(db.games, {
      as: 'game',
      foreignKey: {
        name: 'gameId',
      },
      constraints: false,
    });

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

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




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

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



  return content_items;
};


