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

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"commande",


"paiement",


"reservation",


"avis",


"stock",


"geofence"

        ],

      },

audience: {
        type: DataTypes.ENUM,
      
      

        values: [

"admins",


"personnel",


"client",


"role_cible",


"utilisateur_cible"

        ],

      },

order_nature: {
        type: DataTypes.ENUM,
      
      

        values: [

"nourriture",


"boisson",


"mixte",


"na"

        ],

      },

quantity_total: {
        type: DataTypes.INTEGER,
      
      

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

message: {
        type: DataTypes.TEXT,
      
      

      },

event_time: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  notification_events.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_events.belongsTo(db.restaurants, {
      as: 'restaurant',
      foreignKey: {
        name: 'restaurantId',
      },
      constraints: false,
    });

    db.notification_events.belongsTo(db.users, {
      as: 'target_user',
      foreignKey: {
        name: 'target_userId',
      },
      constraints: false,
    });




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

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



  return notification_events;
};


