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

recommendation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"feed_post",


"suggested_user",


"suggested_group",


"suggested_hashtag"

        ],

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

reason_text: {
        type: DataTypes.TEXT,
      
      

      },

generated_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

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

  ai_recommendations.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.ai_recommendations.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.ai_recommendations.belongsTo(db.posts, {
      as: 'post',
      foreignKey: {
        name: 'postId',
      },
      constraints: false,
    });

    db.ai_recommendations.belongsTo(db.users, {
      as: 'suggested_user',
      foreignKey: {
        name: 'suggested_userId',
      },
      constraints: false,
    });

    db.ai_recommendations.belongsTo(db.groups, {
      as: 'group',
      foreignKey: {
        name: 'groupId',
      },
      constraints: false,
    });

    db.ai_recommendations.belongsTo(db.hashtags, {
      as: 'hashtag',
      foreignKey: {
        name: 'hashtagId',
      },
      constraints: false,
    });




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

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



  return ai_recommendations;
};


