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

distance_meters: {
        type: DataTypes.DECIMAL,
      
      

      },

latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

alert_time: {
        type: DataTypes.DATE,
      
      

      },

severity: {
        type: DataTypes.ENUM,
      
      

        values: [

"info",


"warning",


"critical"

        ],

      },

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

      },

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

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

    db.geofence_alerts.belongsTo(db.users, {
      as: 'staff_user',
      foreignKey: {
        name: 'staff_userId',
      },
      constraints: false,
    });

    db.geofence_alerts.belongsTo(db.users, {
      as: 'acknowledged_by_user',
      foreignKey: {
        name: 'acknowledged_by_userId',
      },
      constraints: false,
    });




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

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



  return geofence_alerts;
};


