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

name_om: {
        type: DataTypes.TEXT,
      
      

      },

name_am: {
        type: DataTypes.TEXT,
      
      

      },

name_en: {
        type: DataTypes.TEXT,
      
      

      },

stream_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"natural",


"social",


"general"

        ],

      },

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

  streams.associate = (db) => {


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











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



    db.streams.hasMany(db.students, {
      as: 'students_current_stream',
      foreignKey: {
          name: 'current_streamId',
      },
      constraints: false,
    });


    db.streams.hasMany(db.class_sections, {
      as: 'class_sections_stream',
      foreignKey: {
          name: 'streamId',
      },
      constraints: false,
    });








    db.streams.hasMany(db.study_materials, {
      as: 'study_materials_stream',
      foreignKey: {
          name: 'streamId',
      },
      constraints: false,
    });


    db.streams.hasMany(db.exams, {
      as: 'exams_stream',
      foreignKey: {
          name: 'streamId',
      },
      constraints: false,
    });










    db.streams.hasMany(db.admission_applications, {
      as: 'admission_applications_requested_stream',
      foreignKey: {
          name: 'requested_streamId',
      },
      constraints: false,
    });








//end loop






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

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



  return streams;
};


