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

enrollment_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"teacher",


"assistant",


"student"

        ],

      },

enrollment_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"invited",


"dropped",


"completed"

        ],

      },

enrolled_at: {
        type: DataTypes.DATE,
      
      

      },

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

  course_enrollments.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.course_enrollments.belongsTo(db.courses, {
      as: 'course',
      foreignKey: {
        name: 'courseId',
      },
      constraints: false,
    });

    db.course_enrollments.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return course_enrollments;
};


