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

read_at: {
        type: DataTypes.DATE,
      
      

      },

delivery_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"delivered",


"failed"

        ],

      },

archived: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  message_recipients.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_recipients.belongsTo(db.messages, {
      as: 'message',
      foreignKey: {
        name: 'messageId',
      },
      constraints: false,
    });

    db.message_recipients.belongsTo(db.users, {
      as: 'recipient',
      foreignKey: {
        name: 'recipientId',
      },
      constraints: false,
    });




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

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



  return message_recipients;
};


