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

followed_at: {
        type: DataTypes.DATE,
      
      

      },

notifications_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

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

    db.follows.belongsTo(db.creator_profiles, {
      as: 'followed_creator',
      foreignKey: {
        name: 'followed_creatorId',
      },
      constraints: false,
    });

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




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

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



  return follows;
};


