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

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"whatsapp",


"email",


"in_app"

        ],

      },

message_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"payslip",


"attendance_alert",


"generic"

        ],

      },

recipient: {
        type: DataTypes.TEXT,
      
      

      },

subject: {
        type: DataTypes.TEXT,
      
      

      },

body: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"sent",


"failed"

        ],

      },

queued_at: {
        type: DataTypes.DATE,
      
      

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

provider_message_id: {
        type: DataTypes.TEXT,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  notification_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.notification_messages.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return notification_messages;
};


