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

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"push",


"sms",


"email",


"voice"

        ],

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

delivery_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"sent",


"delivered",


"failed"

        ],

      },

provider_message_id: {
        type: DataTypes.TEXT,
      
      

      },

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

  alert_notifications.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.alert_notifications.belongsTo(db.alerts, {
      as: 'alert',
      foreignKey: {
        name: 'alertId',
      },
      constraints: false,
    });

    db.alert_notifications.belongsTo(db.users, {
      as: 'recipient_user',
      foreignKey: {
        name: 'recipient_userId',
      },
      constraints: false,
    });

    db.alert_notifications.belongsTo(db.accounts, {
      as: 'accounts',
      foreignKey: {
        name: 'accountsId',
      },
      constraints: false,
    });




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

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



  return alert_notifications;
};


