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

clicked_at: {
        type: DataTypes.DATE,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

city: {
        type: DataTypes.TEXT,
      
      

      },

referrer: {
        type: DataTypes.TEXT,
      
      

      },

utm_source: {
        type: DataTypes.TEXT,
      
      

      },

utm_campaign: {
        type: DataTypes.TEXT,
      
      

      },

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

  smart_link_clicks.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.smart_link_clicks.belongsTo(db.smart_links, {
      as: 'smart_link',
      foreignKey: {
        name: 'smart_linkId',
      },
      constraints: false,
    });

    db.smart_link_clicks.belongsTo(db.distribution_platforms, {
      as: 'platform',
      foreignKey: {
        name: 'platformId',
      },
      constraints: false,
    });

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




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

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



  return smart_link_clicks;
};


