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

learning_objectives_om: {
        type: DataTypes.TEXT,
      
      

      },

learning_objectives_am: {
        type: DataTypes.TEXT,
      
      

      },

learning_objectives_en: {
        type: DataTypes.TEXT,
      
      

      },

topics_outline: {
        type: DataTypes.TEXT,
      
      

      },

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

  subject_offerings.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.subject_offerings.belongsTo(db.subjects, {
      as: 'subject',
      foreignKey: {
        name: 'subjectId',
      },
      constraints: false,
    });

    db.subject_offerings.belongsTo(db.grades, {
      as: 'grade',
      foreignKey: {
        name: 'gradeId',
      },
      constraints: false,
    });

    db.subject_offerings.belongsTo(db.streams, {
      as: 'stream',
      foreignKey: {
        name: 'streamId',
      },
      constraints: false,
    });

    db.subject_offerings.belongsTo(db.staff_members, {
      as: 'responsible_teacher',
      foreignKey: {
        name: 'responsible_teacherId',
      },
      constraints: false,
    });




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

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



  return subject_offerings;
};


