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

name: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.TEXT,
      
      

      },

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

  interests.associate = (db) => {


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









    db.interests.hasMany(db.user_interests, {
      as: 'user_interests_interest',
      foreignKey: {
          name: 'interestId',
      },
      constraints: false,
    });




















//end loop






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

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



  return interests;
};


