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

attachment_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"image",


"file"

        ],

      },

caption: {
        type: DataTypes.TEXT,
      
      

      },

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

  message_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.message_attachments.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



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

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


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

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



  return message_attachments;
};


