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

viewed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  story_views.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.story_views.belongsTo(db.stories, {
      as: 'story',
      foreignKey: {
        name: 'storyId',
      },
      constraints: false,
    });

    db.story_views.belongsTo(db.users, {
      as: 'viewer',
      foreignKey: {
        name: 'viewerId',
      },
      constraints: false,
    });




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

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



  return story_views;
};


