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

title: {
        type: DataTypes.TEXT,
      
      

      },

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

  activity_files.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.activity_files.belongsTo(db.activities, {
      as: 'activity',
      foreignKey: {
        name: 'activityId',
      },
      constraints: false,
    });



    db.activity_files.hasMany(db.file, {
      as: 'file',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.activity_files.getTableName(),
        belongsToColumn: 'file',
      },
    });


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

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



  return activity_files;
};


