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

title: {
        type: DataTypes.TEXT,
      
      

      },

url: {
        type: DataTypes.TEXT,
      
      

      },

snippet: {
        type: DataTypes.TEXT,
      
      

      },

fetched_at: {
        type: DataTypes.DATE,
      
      

      },

rank: {
        type: DataTypes.INTEGER,
      
      

      },

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

  web_search_results.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.web_search_results.belongsTo(db.web_search_queries, {
      as: 'query',
      foreignKey: {
        name: 'queryId',
      },
      constraints: false,
    });

    db.web_search_results.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return web_search_results;
};


