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

query_text: {
        type: DataTypes.TEXT,
      
      

      },

search_latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

search_longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

radius_km: {
        type: DataTypes.DECIMAL,
      
      

      },

searched_at: {
        type: DataTypes.DATE,
      
      

      },

results_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

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

    db.search_logs.belongsTo(db.place_categories, {
      as: 'category',
      foreignKey: {
        name: 'categoryId',
      },
      constraints: false,
    });




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

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



  return search_logs;
};


