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

geofence_name: {
        type: DataTypes.TEXT,
      
      

      },

shape_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"circle",


"polygon"

        ],

      },

center_latitude: {
        type: DataTypes.DECIMAL,
      
      

      },

center_longitude: {
        type: DataTypes.DECIMAL,
      
      

      },

radius_meters: {
        type: DataTypes.DECIMAL,
      
      

      },

polygon_points: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

alert_on: {
        type: DataTypes.ENUM,
      
      

        values: [

"enter",


"exit",


"enter_or_exit"

        ],

      },

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

  geofences.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.geofences.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

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




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

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



  return geofences;
};


