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

message: {
        type: DataTypes.TEXT,
      
      

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

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

  support_ticket_messages.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.support_ticket_messages.belongsTo(db.support_tickets, {
      as: 'support_ticket',
      foreignKey: {
        name: 'support_ticketId',
      },
      constraints: false,
    });

    db.support_ticket_messages.belongsTo(db.users, {
      as: 'author_user',
      foreignKey: {
        name: 'author_userId',
      },
      constraints: false,
    });

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



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


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

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



  return support_ticket_messages;
};


