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

content_type: {
        type: DataTypes.TEXT,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  report_attachments.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.report_attachments.belongsTo(db.reports, {
      as: 'report',
      foreignKey: {
        name: 'reportId',
      },
      constraints: false,
    });



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


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

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



  return report_attachments;
};


