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

name_bn: {
        type: DataTypes.TEXT,
      
      

      },

name_en: {
        type: DataTypes.TEXT,
      
      

      },

icon_key: {
        type: DataTypes.TEXT,
      
      

      },

seed_tutor_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

  subject_categories.associate = (db) => {


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








    db.subject_categories.hasMany(db.subjects, {
      as: 'subjects_category',
      foreignKey: {
          name: 'categoryId',
      },
      constraints: false,
    });



    db.subject_categories.hasMany(db.gigs, {
      as: 'gigs_category',
      foreignKey: {
          name: 'categoryId',
      },
      constraints: false,
    });















    db.subject_categories.hasMany(db.spaces, {
      as: 'spaces_category',
      foreignKey: {
          name: 'categoryId',
      },
      constraints: false,
    });





















//end loop






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

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



  return subject_categories;
};


